home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / amicvs1-0.lha / AmiCVS / emacs / lisp-adds / pcl-cvs / pcl-cvs.el < prev    next >
Encoding:
Text File  |  1994-11-04  |  77.2 KB  |  2,268 lines

  1. ;;; @(#) Id: pcl-cvs.el,v 1.93 1993/05/31 22:44:00 ceder Exp 
  2. ;;; pcl-cvs.el -- A Front-end to CVS 1.3 or later.  Release 1.05.
  3. ;;; Copyright (C) 1991, 1992, 1993  Per Cederqvist
  4. ;;;
  5. ;;; Modified to run on Amiga by Reiner B. Nix 4-Nov-94.
  6. ;;; See lines "[rbn] Amiga" to find changes.
  7. ;;;
  8. ;;; This program is free software; you can redistribute it and/or modify
  9. ;;; it under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 2 of the License, or
  11. ;;; (at your option) any later version.
  12. ;;;
  13. ;;; This program is distributed in the hope that it will be useful,
  14. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with this program; if not, write to the Free Software
  20. ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. ;;;; See below for installation instructions.
  23. ;;;;
  24. ;;;; There is an TeXinfo file that describes this package.  The GNU
  25. ;;;; General Public License is included in that file.  You should read
  26. ;;;; it to get the most from this package.
  27.  
  28. ;;;; Send bug reports and improvements to ceder@lysator.liu.se or
  29. ;;;; ceder@signum.se.  Talk some about Signum Support here. +++FIXME
  30.  
  31. ;;; Don't try to use this with CVS 1.2 or earlier. It won't work. Get
  32. ;;; CVS 1.3. This package works together with RCS 5.6 and probably 5.5
  33. ;;; as well.
  34.  
  35. ;;; Mail questions and bug reports to ceder@lysator.liu.se.
  36.  
  37. (require 'cookie)
  38. (provide 'pcl-cvs)
  39.  
  40. ;;; -------------------------------------------------------
  41. ;;;        START OF THINGS TO CHECK WHEN INSTALLING
  42.  
  43. (defvar cvs-program "/usr/gnu/bin/cvs"
  44.   "*Full path to the cvs executable.")
  45.  
  46. (defvar cvs-diff-program "/usr/gnu/bin/diff"
  47.   "*Full path to the diff program.")
  48.  
  49. (defvar cvs-rmdir-program "/usr/gnu/bin/rmdir"
  50.   "*Full path to the rmdir program. Typically /bin/rmdir.")
  51.  
  52. ;; Variable added to be able to redefine it for customization.
  53. ;; [rbn] Amiga
  54. (defvar cvs-tempdir "/tmp"
  55.   "*Directory for temporary stuff")
  56.  
  57. ;; Uncomment the following line if you are running on 18.57 or earlier.
  58. ;(setq delete-exited-processes nil)
  59. ;; Emacs version 18.57 and earlier is likely to crash if
  60. ;; delete-exited-processes is t, since the sentinel uses lots of
  61. ;; memory, and 18.57 forgets to GCPROT a variable if
  62. ;; delete-exited-processes is t.
  63.  
  64. (defvar cvs-shell "/bin/sh"
  65.   "*Full path to a shell that can do redirection on stdout.")
  66.  
  67. ;;;         END OF THINGS TO CHECK WHEN INSTALLING
  68. ;;; --------------------------------------------------------
  69.  
  70. (defvar cvs-cvsroot nil
  71.   "*Specifies where the (current) cvs master repository is.
  72. Overrides the $CVSROOT variable by sending \" -d dir\" to all cvs commands.
  73. This switch is useful if you have multiple CVS repositories.")
  74.  
  75. (defvar cvs-stdout-file nil
  76.   "Name of the file that holds the output that CVS sends to stdout.
  77. This variable is buffer local.")
  78.  
  79. (defvar cvs-lock-file nil
  80.   "Full path to a lock file that CVS is waiting for (or was waiting for).")
  81.  
  82. (defvar cvs-bakprefix ".#"
  83.   "The prefix that CVS prepends to files when rcsmerge'ing.")
  84.  
  85. (defvar cvs-erase-input-buffer nil
  86.   "*Non-nil if input buffers should be cleared before asking for new info.")
  87.  
  88. (defvar cvs-auto-remove-handled nil
  89.   "*Non-nil if cvs-mode-remove-handled should be called automatically.
  90. If this is set to any non-nil value entries that does not need to be
  91. checked in will be removed from the *cvs* buffer after every cvs-mode-commit
  92. command.")
  93.  
  94. (defvar cvs-sort-ignore-file t
  95.   "*Non-nil if cvs-mode-ignore should sort the .cvsignore automatically.")
  96.  
  97. (defvar cvs-auto-revert-after-commit t
  98.   "*Non-nil if committed buffers should be automatically reverted.")
  99.  
  100. (defconst cvs-cursor-column 14
  101.   "Column to position cursor in in cvs-mode.
  102. Column 0 is left-most column.")
  103.  
  104. (defvar cvs-mode-map nil
  105.   "Keymap for the cvs mode.")
  106.  
  107. (defvar cvs-edit-mode-map nil
  108.   "Keymap for the cvs edit mode (used when editing cvs log messages).")
  109.  
  110. (defvar cvs-buffer-name "*cvs*"
  111.   "Name of the cvs buffer.")
  112.  
  113. (defvar cvs-commit-prompt-buffer "*cvs-commit-message*"
  114.   "Name of buffer in which the user is prompted for a log message when
  115. committing files.")
  116.  
  117. (defvar cvs-commit-buffer-require-final-newline t
  118.   "*t says silently put a newline at the end of commit log messages.
  119. Non-nil but not t says ask user whether to add a newline in each such case.
  120. nil means don't add newlines.")
  121.  
  122. (defvar cvs-temp-buffer-name "*cvs-tmp*"
  123.   "*Name of the cvs temporary buffer.
  124. Output from cvs is placed here by synchronous commands.")
  125.  
  126. (defvar cvs-diff-ignore-marks nil
  127.   "*Non-nil if cvs-diff and cvs-mode-diff-backup should ignore any marked files.
  128. Normally they run diff on the files that are marked (with cvs-mode-mark),
  129. or the file under the cursor if no files are marked.  If this variable
  130. is set to a non-nil value they will always run diff on the file on the
  131. current line.")
  132.  
  133. (defvar cvs-status-flags nil
  134.   "*List of strings to pass to ``cvs status''.")
  135.  
  136. (defvar cvs-log-flags nil
  137.   "*List of strings to pass to ``cvs log''.")
  138.  
  139. (defvar cvs-diff-flags nil
  140.   "*List of strings to use as flags to pass to ``diff'' and ``cvs diff''.
  141. Used by cvs-mode-diff-cvs and cvs-mode-diff-backup.
  142. Set this to '(\"-u\") to get a Unidiff format, or '(\"-c\") to get context diffs.")
  143.  
  144. (defvar cvs-update-prog-output-skip-regexp "$"
  145.   "*A regexp that matches the end of the output from all cvs update programs.
  146. That is, output from any programs that are run by CVS (by the flag -u
  147. in the `modules' file - see cvs(5)) when `cvs update' is performed should
  148. terminate with a line that this regexp matches.  It is enough that
  149. some part of the line is matched.
  150.  
  151. The default (a single $) fits programs without output.")
  152.  
  153. ;; The variables below are used internally by pcl-cvs. You should
  154. ;; never change them.
  155.  
  156. (defvar cvs-buffers-to-delete nil
  157.   "List of temporary buffers that should be discarded as soon as possible.
  158. Due to a bug in emacs 18.57 the sentinel can't discard them reliably.")
  159.  
  160. ;; You are NOT allowed to disable this message by default.  However, you
  161. ;; are encouraged to inform your users that by adding
  162. ;;    (setq cvs-inhibit-copyright-message t)
  163. ;; to their .emacs they can get rid of it.  Just don't add that line
  164. ;; to your default.el!
  165. (defvar cvs-inhibit-copyright-message nil
  166.   "*Non-nil means don't display a Copyright message in the ``*cvs*'' buffer.")
  167.  
  168. (defconst pcl-cvs-version "1.05"
  169.   "A string denoting the current release version of pcl-cvs.")
  170.  
  171. (defconst cvs-startup-message
  172.   (if cvs-inhibit-copyright-message
  173.       "PCL-CVS release 1.05"
  174.     "PCL-CVS release 1.05.  Copyright (C) 1992, 1993 Per Cederqvist
  175. Modified to run on Amiga by Reiner B. Nix 4-Nov-94.
  176. Pcl-cvs comes with absolutely no warranty; for details consult the manual.
  177. This is free software, and you are welcome to redistribute it under certain
  178. conditions; again, consult the TeXinfo manual for details.")
  179.   "*Startup message for CVS.")
  180.  
  181. (defvar cvs-update-running nil
  182.   "This is set to nil when no process is running, and to
  183. the process when a cvs update process is running.")
  184.  
  185. (defvar cvs-cookie-handle nil
  186.   "Handle for the cookie structure that is displayed in the *cvs* buffer.")
  187.  
  188. (defvar cvs-mode-commit nil
  189.   "Used internally by pcl-cvs.")
  190.  
  191. ;;; The cvs data structure:
  192. ;;;
  193. ;;; When the `cvs update' is ready we parse the output. Every file
  194. ;;; that is affected in some way is added as a cookie of fileinfo
  195. ;;; (as defined below).
  196. ;;;
  197.  
  198. ;;; cvs-fileinfo
  199. ;;;
  200. ;;;  marked         t/nil
  201. ;;;  type         One of
  202. ;;;               UPDATED    - file copied from repository
  203. ;;;               MODIFIED   - modified by you, unchanged in
  204. ;;;                    repository
  205. ;;;               ADDED      - added by you, not yet committed
  206. ;;;               REMOVED    - removed by you, not yet committed
  207. ;;;               CVS-REMOVED- removed, since file no longer exists
  208. ;;;                    in the repository.
  209. ;;;               MERGED     - successful merge
  210. ;;;               CONFLICT   - conflict when merging
  211. ;;;               REM-CONFLICT-removed in repository, changed locally.
  212. ;;;               MOD-CONFLICT-removed locally, changed in repository.
  213. ;;;                        REM-EXIST  -removed locally, but still exists.
  214. ;;;               DIRCHANGE  - A change of directory.
  215. ;;;               UNKNOWN    - An unknown file.
  216. ;;;               MOVE-AWAY  - A file that is in the way.
  217. ;;;               REPOS-MISSING- The directory is removed from the
  218. ;;;                      repository. Go fetch a backup.
  219. ;;;                        MESSAGE    - This is a special fileinfo that is used
  220. ;;;                            to display a text that should be in
  221. ;;;                                       full-log.
  222. ;;;  dir         Directory the file resides in. Should not end with
  223. ;;;             slash.
  224. ;;;  file-name         The file name.
  225. ;;;  base-revision       The revision that the working file was based on.
  226. ;;;                      Onlyy valid for MERGED and CONFLICT files.
  227. ;;;  cvs-diff-buffer     A buffer that contains a 'cvs diff file'.
  228. ;;;  backup-diff-buffer     A buffer that contains a 'diff file backup-file'.
  229. ;;;  full-log         The output from cvs, unparsed.
  230. ;;;  mod-time         Modification time of file used for *-diff-buffer.
  231. ;;;  handled         True if this file doesn't require further action.
  232. ;;; 
  233. ;;; Constructor:
  234.  
  235. ;;; cvs-fileinfo
  236.  
  237. ;;; Constructor:
  238.  
  239. (defun cvs-create-fileinfo (type
  240.                 dir
  241.                 file-name
  242.                 full-log)
  243.   "Create a fileinfo from all parameters.
  244. Arguments: TYPE DIR FILE-NAME FULL-LOG.
  245. A fileinfo has the following fields:
  246.  
  247.   marked        t/nil
  248.   type              One of
  249.             UPDATED       - file copied from repository
  250.             MODIFIED   - modified by you, unchanged in
  251.                      repository
  252.             ADDED       - added by you, not yet committed
  253.             REMOVED       - removed by you, not yet committed
  254.             CVS-REMOVED- removed, since file no longer exists
  255.                      in the repository.
  256.             MERGED       - successful merge
  257.             CONFLICT   - conflict when merging
  258.             REM-CONFLICT-removed in repository, but altered
  259.                      locally.
  260.             MOD-CONFLICT-removed locally, changed in repository.
  261.                         REM-EXIST  - removed locally, but still exists.
  262.             DIRCHANGE  - A change of directory.
  263.             UNKNOWN       - An unknown file.
  264.             MOVE-AWAY  - A file that is in the way.
  265.             REPOS-MISSING- The directory has vanished from the
  266.                        repository.
  267.                         MESSAGE    - This is a special fileinfo that is used
  268.                          to display a text that should be in
  269.                                        full-log.
  270.   dir              Directory the file resides in. Should not end with slash.
  271.   file-name          The file name.
  272.   backup-file          Name of the backup file if MERGED or CONFLICT.
  273.   cvs-diff-buffer     A buffer that contains a 'cvs diff file'.
  274.   backup-diff-buffer  A buffer that contains a 'diff file backup-file'.
  275.   full-log          The output from cvs, unparsed.
  276.   mod-time          Modification time of file used for *-diff-buffer.
  277.   handled          True if this file doesn't require further action."
  278.   (cons
  279.    'CVS-FILEINFO
  280.    (vector nil nil type dir file-name nil nil nil full-log nil)))
  281.  
  282.  
  283. ;;; Selectors:
  284.  
  285. (defun cvs-fileinfo->handled (cvs-fileinfo)
  286.   "Get the  `handled' field from CVS-FILEINFO."
  287.   (elt (cdr cvs-fileinfo) 0))
  288.  
  289. (defun cvs-fileinfo->marked (cvs-fileinfo)
  290.   "Check if CVS-FILEINFO is marked."
  291.   (elt (cdr cvs-fileinfo) 1))
  292.  
  293. (defun cvs-fileinfo->type (cvs-fileinfo)
  294.   "Get type from CVS-FILEINFO.
  295. Type is one of UPDATED, MODIFIED, ADDED, REMOVED, CVS-REMOVED, MERGED,
  296. CONFLICT, REM-CONFLICT, MOD-CONFLICT, REM-EXIST, DIRCHANGE, UNKNOWN, MOVE-AWAY,
  297. REPOS-MISSING or MESSAGE."
  298.   (elt (cdr cvs-fileinfo) 2))
  299.  
  300. (defun cvs-fileinfo->dir (cvs-fileinfo)
  301.   "Get dir from CVS-FILEINFO.
  302. The directory name does not end with a slash. "
  303.   (elt (cdr cvs-fileinfo) 3))
  304.  
  305. (defun cvs-fileinfo->file-name (cvs-fileinfo)
  306.   "Get file-name from CVS-FILEINFO."
  307.   (elt (cdr cvs-fileinfo) 4))
  308.  
  309. (defun cvs-fileinfo->base-revision (cvs-fileinfo)
  310.   "Get the base revision from CVS-FILEINFO."
  311.   (elt (cdr cvs-fileinfo) 5))
  312.  
  313. (defun cvs-fileinfo->cvs-diff-buffer (cvs-fileinfo)
  314.   "Get cvs-diff-buffer from CVS-FILEINFO."
  315.   (elt (cdr cvs-fileinfo) 6))
  316.  
  317. (defun cvs-fileinfo->backup-diff-buffer (cvs-fileinfo)
  318.   "Get backup-diff-buffer from CVS-FILEINFO."
  319.   (elt (cdr cvs-fileinfo) 7))
  320.  
  321. (defun cvs-fileinfo->full-log (cvs-fileinfo)
  322.   "Get full-log from CVS-FILEINFO."
  323.   (elt (cdr cvs-fileinfo) 8))
  324.  
  325. (defun cvs-fileinfo->mod-time (cvs-fileinfo)
  326.   "Get mod-time from CVS-FILEINFO."
  327.   (elt (cdr cvs-fileinfo) 9))
  328.  
  329. ;;; Modifiers:
  330.  
  331. (defun cvs-set-fileinfo->handled (cvs-fileinfo newval)
  332.   "Set handled in CVS-FILEINFO to NEWVAL."
  333.   (aset (cdr cvs-fileinfo) 0 newval))
  334.  
  335. (defun cvs-set-fileinfo->marked (cvs-fileinfo newval)
  336.   "Set marked in CVS-FILEINFO to NEWVAL."
  337.   (aset (cdr cvs-fileinfo) 1 newval))
  338.  
  339. (defun cvs-set-fileinfo->type (cvs-fileinfo newval)
  340.   "Set type in CVS-FILEINFO to NEWVAL."
  341.   (aset (cdr cvs-fileinfo) 2 newval))
  342.  
  343. (defun cvs-set-fileinfo->dir (cvs-fileinfo newval)
  344.   "Set dir in CVS-FILEINFO to NEWVAL.
  345. The directory should now end with a slash."
  346.   (aset (cdr cvs-fileinfo) 3 newval))
  347.  
  348. (defun cvs-set-fileinfo->file-name (cvs-fileinfo newval)
  349.   "Set file-name in CVS-FILEINFO to NEWVAL."
  350.   (aset (cdr cvs-fileinfo) 4 newval))
  351.  
  352. (defun cvs-set-fileinfo->base-revision (cvs-fileinfo newval)
  353.   "Set base-revision in CVS-FILEINFO to NEWVAL."
  354.   (aset (cdr cvs-fileinfo) 5 newval))
  355.  
  356. (defun cvs-set-fileinfo->cvs-diff-buffer (cvs-fileinfo newval)
  357.   "Set cvs-diff-buffer in CVS-FILEINFO to NEWVAL."
  358.   (aset (cdr cvs-fileinfo) 6 newval))
  359.  
  360. (defun cvs-set-fileinfo->backup-diff-buffer (cvs-fileinfo newval)
  361.   "Set backup-diff-buffer in CVS-FILEINFO to NEWVAL."
  362.   (aset (cdr cvs-fileinfo) 7 newval))
  363.  
  364. (defun cvs-set-fileinfo->full-log (cvs-fileinfo newval)
  365.   "Set full-log in CVS-FILEINFO to NEWVAL."
  366.   (aset (cdr cvs-fileinfo) 8 newval))
  367.  
  368. (defun cvs-set-fileinfo->mod-time (cvs-fileinfo newval)
  369.   "Set full-log in CVS-FILEINFO to NEWVAL."
  370.   (aset (cdr cvs-fileinfo) 9 newval))
  371.  
  372.  
  373.  
  374. ;;; Predicate:
  375.  
  376. (defun cvs-fileinfo-p (object)
  377.   "Return t if OBJECT is a cvs-fileinfo."
  378.   (eq (car-safe object) 'CVS-FILEINFO))
  379.  
  380. ;;;; End of types.
  381.  
  382. (defun cvs-use-temp-buffer ()
  383.   "Display a temporary buffer in another window and select it.
  384. The selected window will not be changed.  The temporary buffer will
  385. be erased and writable."
  386.  
  387.   (let ((dir default-directory))
  388.     (display-buffer (get-buffer-create cvs-temp-buffer-name))
  389.     (set-buffer cvs-temp-buffer-name)
  390.     (setq buffer-read-only nil)
  391.     (setq default-directory dir)
  392.     (erase-buffer)))
  393.  
  394. ; Too complicated to handle all the cases that are generated.
  395. ; Maybe later.
  396. ;(defun cvs-examine (directory &optional local)
  397. ;  "Run a 'cvs -n update' in the current working directory.
  398. ;That is, check what needs to be done, but don't change the disc.
  399. ;Feed the output to a *cvs* buffer and run cvs-mode on it.
  400. ;If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run."
  401. ;  (interactive (list (read-file-name "CVS Update (directory): "
  402. ;                     nil default-directory nil)
  403. ;             current-prefix-arg))
  404. ;  (cvs-do-update directory local 'noupdate))
  405.  
  406. (defun cvs-update (directory &optional local)
  407.   "Run a 'cvs update' in the current working directory. Feed the
  408. output to a *cvs* buffer and run cvs-mode on it.
  409. If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run."
  410.   (interactive (list (read-file-name "CVS Update (directory): "
  411.                      nil default-directory nil)
  412.              current-prefix-arg))
  413.   (cvs-do-update directory local nil)
  414.   (switch-to-buffer cvs-buffer-name))
  415.  
  416. (defun cvs-update-other-window (directory &optional local)
  417.   "Run a 'cvs update' in the current working directory. Feed the
  418. output to a *cvs* buffer, display it in the other window, and run
  419. cvs-mode on it.
  420.  
  421. If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run."
  422.   (interactive (list (read-file-name "CVS Update other window (directory): "
  423.                      nil default-directory nil)
  424.              current-prefix-arg))
  425.   (cvs-do-update directory local nil)
  426.   (switch-to-buffer-other-window cvs-buffer-name))
  427.  
  428. (defun cvs-filter (predicate list &rest extra-args)
  429.   "Apply PREDICATE to each element on LIST.
  430. Args: PREDICATE LIST &rest EXTRA-ARGS.
  431. Return a new list consisting of those elements that PREDICATE
  432. returns non-nil for.
  433.  
  434. If more than two arguments are given the remaining args are
  435. passed to PREDICATE."
  436.   ;; Avoid recursion - this should work for LONG lists also!
  437.   (let* ((head (cons 'dummy-header nil))
  438.      (tail head))
  439.     (while list
  440.       (if (apply predicate (car list) extra-args)
  441.       (setq tail (setcdr tail (list (car list)))))
  442.       (setq list (cdr list)))
  443.     (cdr head)))
  444.  
  445. (defun cvs-mode-update-no-prompt ()
  446.   "Run cvs update in current directory."
  447.   (interactive)
  448.   (cvs-do-update default-directory nil nil))
  449.  
  450. (defun cvs-do-update (directory local dont-change-disc)
  451.   "Do a 'cvs update' in DIRECTORY.
  452. Args: DIRECTORY LOCAL DONT-CHANGE-DISC &optional NOTTHISWINDOW.
  453. If LOCAL is non-nil 'cvs update -l' is executed.
  454. If DONT-CHANGE-DISC is non-nil 'cvs -n update' is executed.
  455. Both LOCAL and DONT-CHANGE-DISC may be non-nil simultaneously.
  456.  
  457. *Note*: DONT-CHANGE-DISC does not yet work. The parser gets confused."
  458.   (save-some-buffers)
  459.   (if (not (file-exists-p cvs-program))
  460.       (error "%s: file not found (check setting of cvs-program)"
  461.          cvs-program))
  462.   (if (not (or (getenv "CVSROOT") cvs-cvsroot))
  463.       (error "Both cvs-cvsroot and environment variable CVSROOT unset."))
  464.   (let* ((this-dir (file-name-as-directory (expand-file-name directory)))
  465.      (update-buffer (generate-new-buffer
  466.              (concat (file-name-nondirectory
  467.                   (substring this-dir 0 -1))
  468.                  "-update")))
  469.      (temp-name (make-temp-name
  470.              (concat (file-name-as-directory
  471.                   (or (getenv "TMPDIR") cvs-tempdir))
  472.                  "pcl-cvs.")))
  473.      (args nil))
  474.  
  475.     ;; Check that this-dir exists and is a directory that is under CVS contr.
  476.  
  477.     (if (not (file-directory-p this-dir))
  478.     (error "%s is not a directory." this-dir))
  479.     (if (not (file-directory-p (concat this-dir "CVS")))
  480.     (error "%s does not contain CVS controlled files." this-dir))
  481.  
  482.     ;; Check that at most one `cvs update' is run at any time.
  483.  
  484.     (if (and cvs-update-running (process-status cvs-update-running)
  485.          (or (eq (process-status cvs-update-running) 'run)
  486.          (eq (process-status cvs-update-running) 'stop)))
  487.     (error "Can't run two `cvs update' simultaneously."))
  488.  
  489.     ;; Generate "-d /master -n update -l".
  490.     (setq args (concat (if cvs-cvsroot (concat " -d " cvs-cvsroot))
  491.                (if dont-change-disc " -n ")
  492.                " update "
  493.                (if local " -l ")))
  494.  
  495.     ;; Set up the buffer that receives the stderr output from "cvs update".
  496.     (set-buffer update-buffer)
  497.     (setq default-directory this-dir)
  498.     (make-local-variable 'cvs-stdout-file)
  499.     (setq cvs-stdout-file temp-name)
  500.  
  501.     (setq cvs-update-running
  502.       (let ((process-connection-type nil)) ; Use a pipe, not a pty.
  503.         (start-process "cvs" update-buffer cvs-shell "-c"
  504.                (concat cvs-program " " args " > " temp-name))))
  505.  
  506.     (setq mode-line-process
  507.       (concat ": "
  508.           (symbol-name (process-status cvs-update-running))))
  509.     (set-buffer-modified-p (buffer-modified-p))    ; Update the mode line.
  510.     (set-process-sentinel cvs-update-running 'cvs-sentinel)
  511.     (set-process-filter cvs-update-running 'cvs-update-filter)
  512.     (set-marker (process-mark cvs-update-running) (point-min))
  513.  
  514.     (save-excursion
  515.       (set-buffer (get-buffer-create cvs-buffer-name))
  516.       (setq buffer-read-only nil)
  517.       (erase-buffer)
  518.       (cvs-mode))
  519.       
  520.     (setq cvs-cookie-handle
  521.       (collection-create
  522.        cvs-buffer-name 'cvs-pp
  523.        cvs-startup-message        ;Se comment above cvs-startup-message.
  524.        "---------- End -----"))
  525.  
  526.     (cookie-enter-first
  527.      cvs-cookie-handle
  528.      (cvs-create-fileinfo
  529.       'MESSAGE nil nil (concat "\n    Running `cvs " args "' in " this-dir
  530.                    "...\n")))
  531.  
  532.     (save-excursion
  533.       (set-buffer cvs-buffer-name)
  534.       (setq mode-line-process
  535.         (concat ": "
  536.             (symbol-name (process-status cvs-update-running))))
  537.       (set-buffer-modified-p (buffer-modified-p))    ; Update the mode line.
  538.       (setq buffer-read-only t))
  539.  
  540.     ;; Work around a bug in emacs 18.57 and earlier.
  541.     (setq cvs-buffers-to-delete
  542.       (cvs-delete-unused-temporary-buffers cvs-buffers-to-delete)))
  543.  
  544.   ;; The following line is said to improve display updates on some
  545.   ;; emacses. It shouldn't be needed, but it does no harm.
  546.   (sit-for 0))
  547.  
  548.  
  549. (defun cvs-delete-unused-temporary-buffers (list)
  550.   "Delete all buffers on LIST that is not visible.
  551. Return a list of all buffers that still is alive."
  552.  
  553.   (cond
  554.    ((null list) nil)
  555.    ((get-buffer-window (car list))
  556.     (cons (car list)
  557.       (cvs-delete-unused-temporary-buffers (cdr list))))
  558.    (t
  559.     (kill-buffer (car list))
  560.     (cvs-delete-unused-temporary-buffers (cdr list)))))
  561.  
  562.  
  563. (put 'cvs-mode 'mode-class 'special)
  564.  
  565. (defun cvs-mode ()
  566.   "\\<cvs-mode-map>Mode used for pcl-cvs, a frontend to CVS.
  567.  
  568. To get the *cvs* buffer you should use ``\\[cvs-update]''.
  569.  
  570. Full documentation is in the Texinfo file.  These are the most useful commands:
  571.  
  572. \\[cvs-mode-previous-line] Move up.                    \\[cvs-mode-next-line] Move down.
  573. \\[cvs-mode-commit]   Commit file.                \\[cvs-mode-update-no-prompt]   Reupdate directory.
  574. \\[cvs-mode-mark]   Mark file/dir.              \\[cvs-mode-unmark]   Unmark file/dir.
  575. \\[cvs-mode-mark-all-files]   Mark all files.             \\[cvs-mode-unmark-all-files]   Unmark all files.
  576. \\[cvs-mode-find-file]   Edit file/run Dired.        \\[cvs-mode-find-file-other-window]   Find file or run Dired in other window.
  577. \\[cvs-mode-remove-handled]   Remove processed entries.   \\[cvs-mode-add-change-log-entry-other-window]   Write ChangeLog in other window.
  578. \\[cvs-mode-add]   Add to repository.          \\[cvs-mode-remove-file]   Remove file.
  579. \\[cvs-mode-diff-cvs]   Diff between base revision. \\[cvs-mode-diff-backup]   Diff backup file.
  580. \\[cvs-mode-emerge]   Run emerge on base revision/backup file.
  581. \\[cvs-mode-acknowledge] Delete line from buffer.    \\[cvs-mode-ignore]   Add file to the .cvsignore file.
  582. \\[cvs-mode-log]   Run ``cvs log''.            \\[cvs-mode-status]   Run ``cvs status''.
  583. \\[cvs-mode-undo-local-changes]  Revert the last checked in version - discard your changes to the file.
  584.  
  585. Entry to this mode runs cvs-mode-hook.
  586. This description is updated for release 1.05 of pcl-cvs.
  587.  
  588. All bindings:
  589. \\{cvs-mode-map}"
  590.   (interactive)
  591.   (setq major-mode 'cvs-mode)
  592.   (setq mode-name "CVS")
  593.   (setq mode-line-process nil)
  594.   (buffer-flush-undo (current-buffer))
  595.   (make-local-variable 'goal-column)
  596.   (setq goal-column cvs-cursor-column)
  597.   (use-local-map cvs-mode-map)
  598.   (run-hooks 'cvs-mode-hook))
  599.  
  600. (defun cvs-sentinel (proc msg)
  601.   "Sentinel for the cvs update process.
  602. This is responsible for parsing the output from the cvs update when
  603. it is finished."
  604.   (cond
  605.    ((null (buffer-name (process-buffer proc)))
  606.     ;; buffer killed
  607.     (set-process-buffer proc nil))
  608.    ((memq (process-status proc) '(signal exit))
  609.     (let* ((obuf (current-buffer))
  610.        (omax (point-max))
  611.        (opoint (point)))
  612.       ;; save-excursion isn't the right thing if
  613.       ;;  process-buffer is current-buffer
  614.       (unwind-protect
  615.       (progn
  616.         (set-buffer (process-buffer proc))
  617.         (setq mode-line-process
  618.           (concat ": "
  619.               (symbol-name (process-status proc))))
  620.         (let* ((out-file cvs-stdout-file)
  621.            (stdout-buffer (find-file-noselect out-file)))
  622.           (cvs-parse-update stdout-buffer (process-buffer proc))
  623.           (setq cvs-buffers-to-delete
  624.             (cons (process-buffer proc)
  625.               (cons stdout-buffer
  626.                 cvs-buffers-to-delete)))
  627.           (delete-file out-file)))
  628.     (set-buffer-modified-p (buffer-modified-p))
  629.     (setq cvs-update-running nil))
  630.       (if (equal obuf (process-buffer proc))
  631.       nil
  632.     (set-buffer (process-buffer proc))
  633.     (if (< opoint omax)
  634.         (goto-char opoint))
  635.     (set-buffer obuf))))))
  636.  
  637. (defun cvs-update-filter (proc string)
  638.   "Filter function for pcl-cvs.
  639. This function gets the output that CVS sends to stderr. It inserts it
  640. into (process-buffer proc) but it also checks if CVS is waiting for a
  641. lock file. If so, it inserts a message cookie in the *cvs* buffer."
  642.   (let ((old-buffer (current-buffer))
  643.     (data (match-data)))
  644.     (unwind-protect
  645.     (progn
  646.            (set-buffer (process-buffer proc))
  647.            (save-excursion
  648.              ;; Insert the text, moving the process-marker.
  649.              (goto-char (process-mark proc))
  650.              (insert string)
  651.              (set-marker (process-mark proc) (point))
  652.         ;; Delete any old lock message
  653.         (if (tin-nth cvs-cookie-handle 1)
  654.         (tin-delete cvs-cookie-handle
  655.                 (tin-nth cvs-cookie-handle 1)))
  656.         ;; Check if CVS is waiting for a lock.
  657.         (beginning-of-line 0)    ;Move to beginning of last
  658.                     ;complete line.
  659.         (cond
  660.          ((looking-at
  661.            "^cvs update: \\[..:..:..\\] waiting \
  662. for \\(.*\\)lock in \\(.*\\)$")
  663.           (setq cvs-lock-file (buffer-substring (match-beginning 2)
  664.                             (match-end 2)))
  665.           (cookie-enter-last
  666.            cvs-cookie-handle
  667.            (cvs-create-fileinfo
  668.         'MESSAGE nil nil
  669.         (concat "\tWaiting for "
  670.             (buffer-substring (match-beginning 1)
  671.                       (match-end 1))
  672.             "lock in " cvs-lock-file
  673.             ".\n\t (type M-x cvs-delete-lock to delete it)")))))))
  674.       (store-match-data data)
  675.       (set-buffer old-buffer))))
  676.  
  677. (defun cvs-delete-lock ()
  678.   "Delete the lock file that CVS is waiting for.
  679. Note that this can be dangerous.  You should only do this
  680. if you are convinced that the process that created the lock is dead."
  681.   (interactive)
  682.   (cond
  683.    ((not (or (file-exists-p
  684.           (concat (file-name-as-directory cvs-lock-file) "#cvs.lock"))
  685.          (cvs-filter (function cvs-lock-file-p)
  686.              (directory-files cvs-lock-file))))
  687.     (error "No lock files found."))
  688.    ((yes-or-no-p (concat "Really delete locks in " cvs-lock-file "? "))
  689.     ;; Re-read the directory -- the locks might have disappeared.
  690.     (let ((locks (cvs-filter (function cvs-lock-file-p)
  691.                  (directory-files cvs-lock-file))))
  692.       (while locks
  693.     (delete-file (concat (file-name-as-directory cvs-lock-file)
  694.                  (car locks)))
  695.     (setq locks (cdr locks)))
  696.       (cvs-remove-directory
  697.        (concat (file-name-as-directory cvs-lock-file) "#cvs.lock"))))))
  698.  
  699. (defun cvs-remove-directory (dir)
  700.   "Remove a directory."
  701.   (if (file-directory-p dir)
  702.       (call-process cvs-rmdir-program nil nil nil dir)
  703.     (error "Not a directory: %s" dir))
  704.   (if (file-exists-p dir)
  705.       (error "Could not remove directory %s" dir)))
  706.  
  707. (defun cvs-lock-file-p (file)
  708.   "Return true if FILE looks like a CVS lock file."
  709.   (or
  710.    (string-match "^#cvs.tfl.[0-9]+$" file)
  711.    (string-match "^#cvs.rfl.[0-9]+$" file)
  712.    (string-match "^#cvs.wfl.[0-9]+$" file)))
  713.  
  714. (defun cvs-skip-line (stdout stderr regexp &optional arg)
  715.   "Like forward-line, but check that the skipped line matches REGEXP.
  716. Args: STDOUT STDERR REGEXP &optional ARG.
  717.  
  718. If it doesn't match REGEXP a bug report is generated and displayed.
  719. STDOUT and STDERR is only used to do that.
  720.  
  721. If optional ARG, a number, is given the ARGth parenthesized expression
  722. in the REGEXP is returned as a string.
  723. Point should be in column 1 when this function is called."
  724.   (cond
  725.    ((looking-at regexp)
  726.     (forward-line 1)
  727.     (if arg
  728.     (buffer-substring (match-beginning arg)
  729.               (match-end arg))))
  730.    (t
  731.     (cvs-parse-error stdout stderr
  732.              (if (eq (current-buffer) stdout) 'STDOUT 'STDERR)
  733.              (point)))))
  734.  
  735. (defun cvs-get-current-dir (root-dir dirname)
  736.   "Return current working directory, suitable for cvs-parse-update.
  737. Args: ROOT-DIR DIRNAME.
  738. Concatenates ROOT-DIR and DIRNAME to form an absolute path."
  739.   (if (string= "." dirname)
  740.       (substring root-dir 0 -1)
  741.     (concat root-dir dirname)))
  742.  
  743. (defun cvs-compare-fileinfos (a b)
  744.   "Compare fileinfo A with fileinfo B and return t if A is `less'."
  745.   (cond
  746.    ;; Sort acording to directories.
  747.    ((string< (cvs-fileinfo->dir a) (cvs-fileinfo->dir b)) t)
  748.    ((not (string= (cvs-fileinfo->dir a) (cvs-fileinfo->dir b))) nil)
  749.    
  750.    ;; The DIRCHANGE entry is always first within the directory.
  751.    ((and (eq (cvs-fileinfo->type a) 'DIRCHANGE)
  752.      (not (eq (cvs-fileinfo->type b) 'DIRCHANGE))) t)
  753.    ((and (eq (cvs-fileinfo->type b) 'DIRCHANGE)
  754.      (not (eq (cvs-fileinfo->type a) 'DIRCHANGE))) nil)
  755.    ;; All files are sorted by file name.
  756.    ((string< (cvs-fileinfo->file-name a) (cvs-fileinfo->file-name b)))))
  757.  
  758. (defun cvs-parse-error (stdout-buffer stderr-buffer err-buf pos)
  759.   "Handle a parse error when parsing the output from cvs.
  760. Args: STDOUT-BUFFER STDERR-BUFFER ERR-BUF POS.
  761. ERR-BUF should be 'STDOUT or 'STDERR."
  762.   (setq pos (1- pos))
  763.   (set-buffer cvs-buffer-name)
  764.   (setq buffer-read-only nil)
  765.   (erase-buffer)
  766.   (insert "To: ceder@lysator.liu.se\n")
  767.   (insert "Subject: pcl-cvs " pcl-cvs-version " parse error.\n")
  768.   (insert "--text follows this line--\n\n")
  769.   (insert "This bug report is automatically generated by pcl-cvs\n")
  770.   (insert "because it doesn't understand some output from CVS.  Below\n")
  771.   (insert "is detailed information about the error.  Please send\n")
  772.   (insert "this, together with any information you think might be\n")
  773.   (insert "useful for me to fix the bug, to the address above.  But\n")
  774.   (insert "please check the \"known problems\" section of the\n")
  775.   (insert "documentation first.  Note that this buffer contains\n")
  776.   (insert "information that you might consider confidential.  You\n")
  777.   (insert "are encouraged to read through it before sending it.\n")
  778.   (insert "\n")
  779.   (insert "Press C-c C-c to send this email.\n\n")
  780.   (insert "Please state the version of these programs you are using:\n")
  781.   (insert "RCS:  \ndiff: \n\n")
  782.  
  783.   (let* ((stdout (save-excursion (set-buffer stdout-buffer) (buffer-string)))
  784.      (stderr (save-excursion (set-buffer stderr-buffer) (buffer-string)))
  785.      (errstr (if (eq err-buf 'STDOUT) stdout stderr))
  786.      (errline-end (string-match "\n" errstr pos))
  787.      (errline (substring errstr pos errline-end)))
  788.     (insert (format "Offending line (%d chars): >" (- errline-end pos)))
  789.     (insert errline)
  790.     (insert "<\n")
  791.     (insert "Sent to " (symbol-name err-buf) " at pos " (format "%d\n" pos))
  792.     (insert "Emacs-version: " (emacs-version) "\n")
  793.     (insert "Pcl-cvs $" "Id:" "$" ": " "Id: pcl-cvs.el,v 1.93 1993/05/31 22:44:00 ceder Exp \n")
  794.     (insert "\n")
  795.     (insert (format "--- Contents of stdout buffer (%d chars) ---\n"
  796.             (length stdout)))
  797.     (insert stdout)
  798.     (insert "--- End of stdout buffer ---\n")
  799.     (insert (format "--- Contents of stderr buffer (%d chars) ---\n"
  800.             (length stderr)))
  801.     (insert stderr)
  802.     (insert "--- End of stderr buffer ---\n")
  803.     (insert "End of bug report.\n")
  804.     (require 'sendmail)
  805.     (mail-mode)
  806.     (error "CVS parse error - please report this bug.")))
  807.       
  808. (defun cvs-parse-update (stdout-buffer stderr-buffer)
  809.   "Parse the output from `cvs update'.
  810.  
  811. Args: STDOUT-BUFFER STDERR-BUFFER.
  812.  
  813. This functions parses the from `cvs update' (which should be
  814. separated in its stdout- and stderr-components) and prints a
  815. pretty representation of it in the *cvs* buffer.
  816.  
  817. Signals an error if unexpected output was detected in the buffer."
  818.   (let* ((head (cons 'dummy nil))
  819.      (tail (cvs-parse-stderr stdout-buffer stderr-buffer
  820.                  head default-directory))
  821.      (root-dir default-directory))
  822.     (cvs-parse-stdout stdout-buffer stderr-buffer tail root-dir)
  823.     (setq head (sort (cdr head) (function cvs-compare-fileinfos)))
  824.  
  825.     (collection-clear cvs-cookie-handle)
  826.     (collection-append-cookies cvs-cookie-handle head)
  827.     (cvs-remove-stdout-shadows)
  828.     (cvs-remove-empty-directories)
  829.     (set-buffer cvs-buffer-name)
  830.     (cvs-mode)
  831.     (goto-char (point-min))
  832.     (tin-goto-previous cvs-cookie-handle (point-min) 1)
  833.     (setq default-directory root-dir)))
  834.  
  835. (defun cvs-remove-stdout-shadows ()
  836.   "Remove entries in the *cvs* buffer that comes from both stdout and stderr.
  837. If there is two entries for a single file the second one should be
  838. deleted. (Remember that sort uses a stable sort algorithm, so one can
  839. be sure that the stderr entry is always first)."
  840.   (collection-filter-tins cvs-cookie-handle
  841.           (function
  842.            (lambda (tin)
  843.          (not (cvs-shadow-entry-p tin))))))
  844.  
  845. (defun cvs-shadow-entry-p (tin)
  846.   "Return non-nil if TIN is a shadow entry.
  847. Args: TIN.
  848. A TIN is a shadow entry if the previous tin contains the same file."
  849.   (let* ((previous-tin (tin-previous cvs-cookie-handle tin))
  850.      (curr (tin-cookie cvs-cookie-handle tin))
  851.      (prev (and previous-tin
  852.             (tin-cookie cvs-cookie-handle previous-tin))))
  853.     (and
  854.      prev curr
  855.      (string= (cvs-fileinfo->file-name prev) (cvs-fileinfo->file-name curr))
  856.      (string= (cvs-fileinfo->dir prev)       (cvs-fileinfo->dir curr))
  857.      (or
  858.       (and (eq (cvs-fileinfo->type prev) 'CONFLICT)
  859.        (eq (cvs-fileinfo->type curr) 'CONFLICT))
  860.       (and (eq (cvs-fileinfo->type prev) 'MERGED)
  861.        (eq (cvs-fileinfo->type curr) 'MODIFIED))
  862.       (and (eq (cvs-fileinfo->type prev) 'REM-EXIST)
  863.        (eq (cvs-fileinfo->type curr) 'REMOVED))))))
  864.  
  865.  
  866. (defun cvs-parse-stderr (stdout-buffer stderr-buffer head dir)
  867.   "Parse the output from CVS that is written to stderr.
  868. Args: STDOUT-BUFFER STDERR-BUFFER HEAD DIR
  869. STDOUT-BUFFER holds the output that cvs sent to stdout. It is only
  870. used to create a bug report in case there is a parse error.
  871. STDERR-BUFFER is the buffer that holds the output to parse.
  872. HEAD is a cons-cell, the head of the list that is built.
  873. DIR is the directory the `cvs update' was run in.
  874.  
  875. This function returns the last cons-cell in the list that is built."
  876.  
  877.   (save-window-excursion
  878.     (set-buffer stderr-buffer)
  879.     (goto-char (point-min))
  880.     (let ((current-dir dir)
  881.       (root-dir dir))
  882.  
  883.       (while (< (point) (point-max))
  884.     (cond
  885.  
  886.      ;; RCVS support (for now, we simply ignore any output from
  887.      ;; RCVS, including error messages!)
  888.  
  889.      ((looking-at "updating of .* finished$")
  890.       (forward-line 1))
  891.  
  892.      ((looking-at "REMOTE FOLDER:.*")
  893.       (forward-line 1)
  894.       (while (and (< (point) (point-max)) (not (looking-at "phase 2.*")))
  895.         (forward-line 1))
  896.       (forward-line 2))
  897.  
  898.      ((looking-at "turn on remote mode$")
  899.       (forward-line 1)
  900.       (while (and (< (point) (point-max)) (not (looking-at "phase 2.*")))
  901.         (forward-line 1))
  902.       (forward-line 2))
  903.  
  904.      ((looking-at "phase 3.*")
  905.       (goto-char (point-max)))
  906.  
  907.      ;; End of RCVS stuff.
  908.  
  909.      ;; CVS is descending a subdirectory.
  910.      
  911.      ((looking-at "cvs update: Updating \\(.*\\)$")
  912.       (setq current-dir
  913.         (cvs-get-current-dir
  914.          root-dir
  915.          (buffer-substring (match-beginning 1) (match-end 1))))
  916.       (setcdr head (list (cvs-create-fileinfo
  917.                   'DIRCHANGE current-dir
  918.                   nil (buffer-substring (match-beginning 0)
  919.                             (match-end 0)))))
  920.       (setq head (cdr head))
  921.       (forward-line 1))
  922.  
  923.      ;; File removed, since it is removed (by third party) in repository.
  924.        
  925.      ((or (looking-at
  926.            "cvs update: warning: \\(.*\\) is not (any longer) pertinent")
  927.           (looking-at
  928.            "cvs update: \\(.*\\) is no longer in the repository"))
  929.  
  930.       (setcdr head (list (cvs-create-fileinfo
  931.                   'CVS-REMOVED current-dir
  932.                   (file-name-nondirectory
  933.                    (buffer-substring (match-beginning 1)
  934.                          (match-end 1)))
  935.                   (buffer-substring (match-beginning 0)
  936.                         (match-end 0)))))
  937.       (setq head (cdr head))
  938.       (forward-line 1))
  939.  
  940.      ;; File removed by you, but recreated by cvs. Ignored.
  941.  
  942.      ((looking-at "cvs update: warning: .* was lost$")
  943.       (forward-line 1))
  944.  
  945.      ;; A file that has been created by you, but added to the cvs
  946.      ;; repository by another.
  947.  
  948.      ((looking-at "^cvs update: move away \\(.*\\); it is in the way$")
  949.       (setcdr head (list (cvs-create-fileinfo
  950.                   'MOVE-AWAY current-dir
  951.                   (file-name-nondirectory
  952.                    (buffer-substring (match-beginning 1)
  953.                          (match-end 1)))
  954.                   (buffer-substring (match-beginning 0)
  955.                         (match-end 0)))))
  956.       (setq head (cdr head))
  957.       (forward-line 1))
  958.  
  959.      ;; Empty line. Probably inserted by mistake by user (or developer :-)
  960.      ;; Ignore.
  961.  
  962.      ((looking-at "^$")
  963.       (forward-line 1))
  964.  
  965.      ;; Cvs waits for a lock. Ignore.
  966.  
  967.      ((looking-at
  968.        "^cvs update: \\[..:..:..\\] waiting for .*lock in ")
  969.       (forward-line 1))
  970.  
  971.      ;; File removed in repository, but edited by you.
  972.  
  973.      ((looking-at
  974.        "cvs update: conflict: \\(.*\\) is modified but no longer \
  975. in the repository$")
  976.       (setcdr head (list
  977.             (cvs-create-fileinfo
  978.              'REM-CONFLICT current-dir
  979.              (file-name-nondirectory
  980.               (buffer-substring (match-beginning 1) (match-end 1)))
  981.              (buffer-substring (match-beginning 0)
  982.                        (match-end 0)))))
  983.       (setq head (cdr head))
  984.       (forward-line 1))
  985.  
  986.      ((looking-at
  987.        "cvs update: conflict: removed \\(.*\\) was modified by \
  988. second party")
  989.       (setcdr head
  990.           (list
  991.            (cvs-create-fileinfo
  992.             'MOD-CONFLICT current-dir
  993.             (buffer-substring (match-beginning 1) (match-end 1))
  994.             (buffer-substring (match-beginning 0) (match-end 0)))))
  995.       (setq head (cdr head))
  996.       (forward-line 1))
  997.  
  998.      ((looking-at
  999.        "cvs update: \\(.*\\) should be removed and is still there")
  1000.       (setcdr head
  1001.           (list
  1002.            (cvs-create-fileinfo
  1003.             'REM-EXIST current-dir
  1004.             (buffer-substring (match-beginning 1) (match-end 1))
  1005.             (buffer-substring (match-beginning 0) (match-end 0)))))
  1006.       (setq head (cdr head))
  1007.       (forward-line 1))
  1008.  
  1009.      ((looking-at "cvs update: in directory ")
  1010.       (let ((start (point)))
  1011.         (forward-line 1)
  1012.         (cvs-skip-line
  1013.          stdout-buffer stderr-buffer
  1014.          (regexp-quote "cvs [update aborted]: there is no repository "))
  1015.         (setcdr head (list
  1016.               (cvs-create-fileinfo
  1017.                'REPOS-MISSING current-dir
  1018.                nil
  1019.                (buffer-substring start (point)))))
  1020.         (setq head (cdr head))))
  1021.  
  1022.        (t
  1023.  
  1024.     ;; CVS has decided to merge someone elses changes into this
  1025.     ;; document. This leads to a lot of garbage being printed.
  1026.     ;; First there is two lines that contains no information
  1027.     ;; that we skip (but we check that we recognize them).
  1028.  
  1029.     (let ((complex-start (point))
  1030.           initial-revision filename)
  1031.  
  1032.       (cvs-skip-line stdout-buffer stderr-buffer "^RCS file: .*$")
  1033.       (setq initial-revision
  1034.         (cvs-skip-line stdout-buffer stderr-buffer
  1035.                    "^retrieving revision \\(.*\\)$" 1))
  1036.       (cvs-skip-line stdout-buffer stderr-buffer
  1037.              "^retrieving revision .*$")
  1038.  
  1039.       ;; Get the file name from the next line.
  1040.  
  1041.       (setq
  1042.        filename
  1043.        (cvs-skip-line
  1044.         stdout-buffer stderr-buffer
  1045.         "^Merging differences between [0-9.]+ and [0-9.]+ into \\(.*\\)$"
  1046.         1))
  1047.  
  1048.       (cond
  1049.        ;; Was it a conflict?
  1050.        ((looking-at
  1051.          ;; Allow both RCS 5.5 and 5.6. (5.6 prints "rcs" and " warning").
  1052.          "^\\(rcs\\)?merge\\( warning\\)?: overlaps during merge$")
  1053.  
  1054.         ;; Yes, this is a conflict.
  1055.         (cvs-skip-line
  1056.          stdout-buffer stderr-buffer
  1057.          "^\\(rcs\\)?merge\\( warning\\)?: overlaps during merge$")
  1058.  
  1059.         (cvs-skip-line stdout-buffer stderr-buffer
  1060.                "^cvs update: conflicts found in ")
  1061.  
  1062.         (let ((fileinfo
  1063.            (cvs-create-fileinfo
  1064.             'CONFLICT current-dir
  1065.             filename
  1066.             (buffer-substring complex-start (point)))))
  1067.  
  1068.           (cvs-set-fileinfo->base-revision fileinfo initial-revision)
  1069.  
  1070.           (setcdr head (list fileinfo))
  1071.           (setq head (cdr head))))
  1072.  
  1073.        ;; Was it a conflict, and was RCS compiled without DIFF3_BIN?
  1074.  
  1075.        ((looking-at
  1076.          ;; Allow both RCS 5.5 and 5.6. (5.6 prints "rcs" and " warning").
  1077.          "^\\(rcs\\)?merge\\( warning\\)?: overlaps or other probl\
  1078. ems during merge$")
  1079.  
  1080.         ;; Yes, this is a conflict.
  1081.         (cvs-skip-line
  1082.          stdout-buffer stderr-buffer
  1083.          "^\\(rcs\\)?merge\\( warning\\)?: overlaps .*during merge$")
  1084.  
  1085.         (cvs-skip-line stdout-buffer stderr-buffer
  1086.                "^cvs update: could not merge ")
  1087.         (cvs-skip-line stdout-buffer stderr-buffer
  1088.                "^cvs update: restoring .* from backup file ")
  1089.  
  1090.         (let ((fileinfo
  1091.            (cvs-create-fileinfo
  1092.             'CONFLICT current-dir
  1093.             filename
  1094.             (buffer-substring complex-start (point)))))
  1095.  
  1096.           (setcdr head (list fileinfo))
  1097.           (setq head (cdr head))))       
  1098.  
  1099.        (t
  1100.         ;; Not a conflict; it must be a succesful merge.
  1101.         (let ((fileinfo
  1102.            (cvs-create-fileinfo
  1103.             'MERGED current-dir
  1104.             filename
  1105.             (buffer-substring complex-start (point)))))
  1106.           (cvs-set-fileinfo->base-revision fileinfo initial-revision)
  1107.           (setcdr head (list fileinfo))
  1108.           (setq head (cdr head)))))))))))
  1109.   head)
  1110.  
  1111.  
  1112. (defun cvs-parse-stdout (stdout-buffer stderr-buffer head root-dir)
  1113.   "Parse the output from CVS that is written to stderr.
  1114. Args: STDOUT-BUFFER STDERR-BUFFER HEAD ROOT-DIR
  1115. STDOUT-BUFFER is the buffer that holds the output to parse.
  1116. STDERR-BUFFER holds the output that cvs sent to stderr. It is only
  1117. used to create a bug report in case there is a parse error.
  1118.  
  1119. HEAD is a cons-cell, the head of the list that is built.
  1120. ROOT-DIR is the directory the `cvs update' was run in.
  1121.  
  1122. This function doesn't return anything particular."
  1123.   (save-window-excursion
  1124.     (set-buffer stdout-buffer)
  1125.     (goto-char (point-min))
  1126.     (while (< (point) (point-max))
  1127.       (cond
  1128.  
  1129.        ;; M: The file is modified by the user, and untouched in the repository.
  1130.        ;; A: The file is "cvs add"ed, but not "cvs ci"ed.
  1131.        ;; R: The file is "cvs remove"ed, but not "cvs ci"ed.
  1132.        ;; C: Conflict
  1133.        ;; U: The file is copied from the repository.
  1134.        ;; ?: Unknown file.
  1135.  
  1136.  
  1137.        ((looking-at "\\([MARCU?]\\) \\(.*\\)$")
  1138.     (let*
  1139.         ((c         (char-after (match-beginning 1)))
  1140.          (full-path
  1141.           (concat (file-name-as-directory root-dir)
  1142.               (buffer-substring (match-beginning 2) (match-end 2))))
  1143.          (fileinfo (cvs-create-fileinfo
  1144.             (cond ((eq c ?M) 'MODIFIED)
  1145.                   ((eq c ?A) 'ADDED)
  1146.                   ((eq c ?R) 'REMOVED)
  1147.                   ((eq c ?C) 'CONFLICT)
  1148.                   ((eq c ?U) 'UPDATED)
  1149.                   ((eq c ??) 'UNKNOWN))
  1150.             (substring (file-name-directory full-path) 0 -1)
  1151.             (file-name-nondirectory full-path)
  1152.             (buffer-substring (match-beginning 0) (match-end 0)))))
  1153.       ;; Updated files require no further action.
  1154.       (if (eq c ?U)
  1155.           (cvs-set-fileinfo->handled fileinfo t))
  1156.  
  1157.       ;; Link this last on the list.
  1158.       (setcdr head (list fileinfo))
  1159.       (setq head (cdr head))
  1160.       (forward-line 1)))
  1161.  
  1162.        ;; Executing a program because of the -u option in modules.
  1163.        ((looking-at "cvs update: Executing")
  1164.     ;; Skip by any output the program may generate to stdout.
  1165.     ;; Note that pcl-cvs will get seriously confused if the
  1166.     ;; program prints anything to stderr.
  1167.     (re-search-forward cvs-update-prog-output-skip-regexp)
  1168.     (forward-line 1))
  1169.  
  1170.        (t (cvs-parse-error stdout-buffer stderr-buffer 'STDOUT (point)))))))
  1171.  
  1172. (defun cvs-pp (fileinfo)
  1173.   "Pretty print FILEINFO.  Insert a printed representation in current buffer.
  1174. For use by the cookie package."
  1175.  
  1176.   (let ((a (cvs-fileinfo->type fileinfo))
  1177.         (s (if (cvs-fileinfo->marked fileinfo)
  1178.                "*" " "))
  1179.         (f (cvs-fileinfo->file-name fileinfo))
  1180.         (ci (if (cvs-fileinfo->handled fileinfo)
  1181.                 "  " "ci")))
  1182.     (insert
  1183.      (cond
  1184.       ((eq a 'UPDATED)
  1185.        (format "%s Updated     %s" s f))
  1186.       ((eq a 'MODIFIED)
  1187.        (format "%s Modified %s %s" s ci f))
  1188.       ((eq a 'MERGED)
  1189.        (format "%s Merged   %s %s" s ci f))
  1190.       ((eq a 'CONFLICT)
  1191.        (format "%s Conflict    %s" s f))
  1192.       ((eq a 'ADDED)
  1193.        (format "%s Added    %s %s" s ci f))
  1194.       ((eq a 'REMOVED)
  1195.        (format "%s Removed  %s %s" s ci f))
  1196.       ((eq a 'UNKNOWN)
  1197.        (format "%s Unknown     %s" s f))
  1198.       ((eq a 'CVS-REMOVED)
  1199.        (format "%s Removed from repository:  %s" s f))
  1200.       ((eq a 'REM-CONFLICT)
  1201.        (format "%s Conflict: Removed from repository, changed by you: %s" s f))
  1202.       ((eq a 'MOD-CONFLICT)
  1203.        (format "%s Conflict: Removed by you, changed in repository: %s" s f))
  1204.       ((eq a 'REM-EXIST)
  1205.        (format "%s Conflict: Removed by you, but still exists: %s" s f))
  1206.       ((eq a 'DIRCHANGE)
  1207.        (format "\nIn directory %s:"
  1208.            (cvs-fileinfo->dir fileinfo)))
  1209.       ((eq a 'MOVE-AWAY)
  1210.        (format "%s Move away %s - it is in the way" s f))
  1211.       ((eq a 'REPOS-MISSING)
  1212.        (format "  This repository is missing! Remove this dir manually."))
  1213.       ((eq a 'MESSAGE)
  1214.        (cvs-fileinfo->full-log fileinfo))
  1215.       (t
  1216.        (format "%s Internal error! %s" s f))))))
  1217.  
  1218.  
  1219. ;;; You can define your own keymap in .emacs. pcl-cvs.el won't overwrite it.
  1220.  
  1221. (if cvs-mode-map
  1222.     nil
  1223.   (setq cvs-mode-map (make-keymap))
  1224.   (suppress-keymap cvs-mode-map)
  1225.   (define-key cvs-mode-map " "    'cvs-mode-next-line)
  1226.   (define-key cvs-mode-map "?"    'describe-mode)
  1227.   (define-key cvs-mode-map "A"    'cvs-mode-add-change-log-entry-other-window)
  1228.   (define-key cvs-mode-map "M"    'cvs-mode-mark-all-files)
  1229.   (define-key cvs-mode-map "R"    'cvs-mode-revert-updated-buffers)
  1230.   (define-key cvs-mode-map "U"    'cvs-mode-undo-local-changes)
  1231.   (define-key cvs-mode-map "\C-?"  'cvs-mode-unmark-up)
  1232.   (define-key cvs-mode-map "\C-k"  'cvs-mode-acknowledge)
  1233.   (define-key cvs-mode-map "\C-n"  'cvs-mode-next-line)
  1234.   (define-key cvs-mode-map "\C-p"  'cvs-mode-previous-line)
  1235.   (define-key cvs-mode-map "\M-\C-?" 'cvs-mode-unmark-all-files)
  1236.   (define-key cvs-mode-map "a"    'cvs-mode-add)
  1237.   (define-key cvs-mode-map "b"    'cvs-mode-diff-backup)
  1238.   (define-key cvs-mode-map "c"    'cvs-mode-commit)
  1239.   (define-key cvs-mode-map "d"    'cvs-mode-diff-cvs)
  1240.   (define-key cvs-mode-map "e"    'cvs-mode-emerge)
  1241.   (define-key cvs-mode-map "f"    'cvs-mode-find-file)
  1242.   (define-key cvs-mode-map "g"    'cvs-mode-update-no-prompt)
  1243.   (define-key cvs-mode-map "i"    'cvs-mode-ignore)
  1244.   (define-key cvs-mode-map "l"    'cvs-mode-log)
  1245.   (define-key cvs-mode-map "m"    'cvs-mode-mark)
  1246.   (define-key cvs-mode-map "n"    'cvs-mode-next-line)
  1247.   (define-key cvs-mode-map "o"    'cvs-mode-find-file-other-window)
  1248.   (define-key cvs-mode-map "p"    'cvs-mode-previous-line)
  1249.   (define-key cvs-mode-map "q"    'bury-buffer)
  1250.   (define-key cvs-mode-map "r"    'cvs-mode-remove-file)
  1251.   (define-key cvs-mode-map "s"    'cvs-mode-status)
  1252.   (define-key cvs-mode-map "x"    'cvs-mode-remove-handled)
  1253.   (define-key cvs-mode-map "u"    'cvs-mode-unmark))
  1254.  
  1255.  
  1256. (defun cvs-get-marked (&optional ignore-marks)
  1257.   "Return a list of all selected tins.
  1258. If there are any marked tins, and IGNORE-MARKS is nil, return them.
  1259. Otherwise, if the cursor selects a directory, return all files in it.
  1260. Otherwise return (a list containing) the file the cursor points to, or
  1261. an empty list if it doesn't point to a file at all.
  1262.  
  1263. Args: &optional IGNORE-MARKS."
  1264.     
  1265.   (cond
  1266.    ;; Any marked cookies?
  1267.    ((and (not ignore-marks)
  1268.      (collection-collect-tin cvs-cookie-handle 'cvs-fileinfo->marked)))
  1269.    ;; Nope.
  1270.    (t
  1271.     (let ((sel (tin-locate cvs-cookie-handle (point))))
  1272.       (cond
  1273.        ;; If a directory is selected, all it members are returned.
  1274.        ((and sel (eq (cvs-fileinfo->type
  1275.             (tin-cookie cvs-cookie-handle sel))
  1276.                'DIRCHANGE))
  1277.     (collection-collect-tin
  1278.      cvs-cookie-handle 'cvs-dir-member-p
  1279.      (cvs-fileinfo->dir (tin-cookie cvs-cookie-handle sel))))
  1280.        (t
  1281.     (list sel)))))))
  1282.  
  1283.  
  1284. (defun cvs-dir-member-p (fileinfo dir)
  1285.   "Return true if FILEINFO represents a file in directory DIR."
  1286.   (and (not (eq (cvs-fileinfo->type fileinfo) 'DIRCHANGE))
  1287.        (string= (cvs-fileinfo->dir fileinfo) dir)))
  1288.  
  1289. (defun cvs-dir-empty-p (tin)
  1290.   "Return non-nil if TIN is a directory that is empty.
  1291. Args: CVS-BUF TIN."
  1292.   (and (eq (cvs-fileinfo->type (tin-cookie cvs-cookie-handle tin)) 'DIRCHANGE)
  1293.        (or (not (tin-next cvs-cookie-handle tin))
  1294.        (eq (cvs-fileinfo->type
  1295.         (tin-cookie cvs-cookie-handle
  1296.                     (tin-next cvs-cookie-handle tin)))
  1297.            'DIRCHANGE))))
  1298.  
  1299. (defun cvs-mode-revert-updated-buffers ()
  1300.   "Revert any buffers that are UPDATED, MERGED or CONFLICT."
  1301.   (interactive)
  1302.   (cookie-map (function cvs-revert-fileinfo) cvs-cookie-handle))
  1303.  
  1304. (defun cvs-revert-fileinfo (fileinfo)
  1305.   "Revert the buffer that holds the file in FILEINFO if it has changed,
  1306. and if the type is UPDATED, MERGED or CONFLICT."
  1307.   (let* ((type (cvs-fileinfo->type fileinfo))
  1308.      (file (cvs-fileinfo->full-path fileinfo))
  1309.      (buffer (get-file-buffer file)))
  1310.     ;; For a revert to happen...
  1311.     (cond
  1312.      ((and
  1313.        ;; ...the type must be one that justifies a revert...
  1314.        (or (eq type 'UPDATED)
  1315.        (eq type 'MERGED)
  1316.        (eq type 'CONFLICT))
  1317.        ;; ...and the user must be editing the file...
  1318.        buffer)
  1319.       (save-excursion
  1320.     (set-buffer buffer)
  1321.     (cond
  1322.      ((buffer-modified-p)
  1323.       (error "%s: edited since last cvs-update."
  1324.          (buffer-file-name)))
  1325.      ;; Go ahead and revert the file.
  1326.      (t (revert-buffer 'dont-use-auto-save-file 'dont-ask))))))))
  1327.  
  1328.  
  1329. (defun cvs-mode-remove-handled ()
  1330.   "Remove all lines that are handled.
  1331. Empty directories are removed."
  1332.   (interactive)
  1333.   ;; Pass one: remove files that are handled.
  1334.   (collection-filter-cookies cvs-cookie-handle
  1335.          (function
  1336.           (lambda (fileinfo) (not (cvs-fileinfo->handled fileinfo)))))
  1337.   ;; Pass two: remove empty directories.
  1338.   (cvs-remove-empty-directories))
  1339.  
  1340.  
  1341. (defun cvs-remove-empty-directories ()
  1342.   "Remove empty directories in the *cvs* buffer."
  1343.   (collection-filter-tins cvs-cookie-handle
  1344.              (function
  1345.               (lambda (tin)
  1346.             (not (cvs-dir-empty-p tin))))))
  1347.  
  1348. (defun cvs-mode-mark (pos)
  1349.   "Mark a fileinfo. Args: POS.
  1350. If the fileinfo is a directory, all the contents of that directory are
  1351. marked instead. A directory can never be marked.
  1352. POS is a buffer position."
  1353.  
  1354.   (interactive "d")
  1355.  
  1356.   (let* ((tin (tin-locate cvs-cookie-handle pos))
  1357.      (sel (tin-cookie cvs-cookie-handle tin)))
  1358.  
  1359.     (cond
  1360.      ;; Does POS point to a directory? If so, mark all files in that directory.
  1361.      ((eq (cvs-fileinfo->type sel) 'DIRCHANGE)
  1362.       (cookie-map
  1363.        (function (lambda (f dir)
  1364.            (cond
  1365.             ((cvs-dir-member-p f dir)
  1366.              (cvs-set-fileinfo->marked f t)
  1367.              t))))        ;Tell cookie to redisplay this cookie.
  1368.        cvs-cookie-handle
  1369.        (cvs-fileinfo->dir sel)))
  1370.      (t
  1371.       (cvs-set-fileinfo->marked sel t)
  1372.       (tin-invalidate cvs-cookie-handle tin)
  1373.       (tin-goto-next cvs-cookie-handle pos 1)))))
  1374.   
  1375.  
  1376. (defun cvs-committable (tin)
  1377.   "Check if the TIN is committable.
  1378. It is committable if it
  1379.    a) is not handled and
  1380.    b) is either MODIFIED, ADDED, REMOVED, MERGED or CONFLICT."
  1381.   (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  1382.      (type (cvs-fileinfo->type fileinfo)))
  1383.     (and (not (cvs-fileinfo->handled fileinfo))
  1384.      (or (eq type 'MODIFIED)
  1385.          (eq type 'ADDED)
  1386.          (eq type 'REMOVED)
  1387.          (eq type 'MERGED)
  1388.          (eq type 'CONFLICT)))))
  1389.  
  1390. (defun cvs-mode-commit ()
  1391.  
  1392.   "Check in all marked files, or the current file.
  1393. The user will be asked for a log message in a buffer.
  1394. If cvs-erase-input-buffer is non-nil that buffer will be erased.
  1395. Otherwise mark and point will be set around the entire contents of the
  1396. buffer so that it is easy to kill the contents of the buffer with \\[kill-region]."
  1397.  
  1398.   (interactive)
  1399.  
  1400.   (let* ((cvs-buf (current-buffer))
  1401.      (marked (cvs-filter (function cvs-committable)
  1402.                  (cvs-get-marked))))
  1403.     (if (null marked)
  1404.     (error "Nothing to commit!")
  1405.       (pop-to-buffer (get-buffer-create cvs-commit-prompt-buffer))
  1406.       (goto-char (point-min))
  1407.  
  1408.       (if cvs-erase-input-buffer
  1409.       (erase-buffer)
  1410.     (push-mark (point-max)))
  1411.       (cvs-edit-mode)
  1412.       (make-local-variable 'cvs-commit-list)
  1413.       (setq cvs-commit-list marked)
  1414.       (message "Press C-c C-c when you are done editing."))))
  1415.  
  1416.  
  1417. ;;
  1418. ;; original code
  1419. ;;
  1420. ;;;(defun cvs-edit-done ()
  1421. ;;;  "Commit the files to the repository."
  1422. ;;;  (interactive)
  1423. ;;;  (if (null cvs-commit-list)
  1424. ;;;      (error "You have already commited the files"))
  1425. ;;;  (if (and (> (point-max) 1)
  1426. ;;;       (/= (char-after (1- (point-max))) ?\n)
  1427. ;;;       (or (eq cvs-commit-buffer-require-final-newline t)
  1428. ;;;           (and cvs-commit-buffer-require-final-newline
  1429. ;;;            (yes-or-no-p
  1430. ;;;             (format "Buffer %s does not end in newline.  Add one? "
  1431. ;;;                 (buffer-name))))))
  1432. ;;;      (save-excursion
  1433. ;;;    (goto-char (point-max))
  1434. ;;;    (insert ?\n)))
  1435. ;;;  (save-some-buffers)
  1436. ;;;  (let ((cc-list cvs-commit-list)
  1437. ;;;    (cc-buffer (get-buffer cvs-buffer-name))
  1438. ;;;    (msg-buffer (current-buffer))
  1439. ;;;    (msg (buffer-substring (point-min) (point-max))))
  1440. ;;;    (pop-to-buffer cc-buffer)
  1441. ;;;    (bury-buffer msg-buffer)
  1442. ;;;    (cvs-use-temp-buffer)
  1443. ;;;    (message "Committing...")
  1444. ;;;    (if (cvs-execute-list cc-list cvs-program
  1445. ;;;              (if cvs-cvsroot
  1446. ;;;                  (list "-d" cvs-cvsroot "commit" "-m" msg)
  1447. ;;;                (list "commit" "-m" msg)))
  1448. ;;;    (error "Something went wrong. Check the %s buffer carefully."
  1449. ;;;           cvs-temp-buffer-name))
  1450. ;;;    (let ((ccl cc-list))
  1451. ;;;      (while ccl
  1452. ;;;    (cvs-after-commit-function (tin-cookie cvs-cookie-handle (car ccl)))
  1453. ;;;    (setq ccl (cdr ccl))))
  1454. ;;;    (apply 'tin-invalidate cvs-cookie-handle cc-list)
  1455. ;;;    (set-buffer msg-buffer)
  1456. ;;;    (setq cvs-commit-list nil)
  1457. ;;;    (set-buffer cc-buffer)
  1458. ;;;    (if cvs-auto-remove-handled
  1459. ;;;    (cvs-mode-remove-handled)))
  1460. ;;;  
  1461. ;;;  (message "Committing... Done."))
  1462.  
  1463.  
  1464. ;;
  1465. ;; modified function using a temporary file for the log message
  1466. ;; [rbn] on Amiga
  1467. ;;
  1468. (defun cvs-edit-done ()
  1469.   "Commit the files to the repository."
  1470.   (interactive)
  1471.   (if (null cvs-commit-list)
  1472.       (error "You have already commited the files"))
  1473.   (if (and (> (point-max) 1)
  1474.        (/= (char-after (1- (point-max))) ?\n)
  1475.        (or (eq cvs-commit-buffer-require-final-newline t)
  1476.            (and cvs-commit-buffer-require-final-newline
  1477.             (yes-or-no-p
  1478.              (format "Buffer %s does not end in newline.  Add one? "
  1479.                  (buffer-name))))))
  1480.       (save-excursion
  1481.     (goto-char (point-max))
  1482.     (insert ?\n)))
  1483.   (save-some-buffers)
  1484.   (let ((cc-list cvs-commit-list)
  1485.     (cc-buffer (get-buffer cvs-buffer-name))
  1486.     (msg-buffer (current-buffer))
  1487.     (msg-file-name (concat "T:" (make-temp-name "pcl-cvs"))))
  1488.     (write-region (point-min) (point-max) msg-file-name)
  1489.     (pop-to-buffer cc-buffer)
  1490.     (bury-buffer msg-buffer)
  1491.     (cvs-use-temp-buffer)
  1492.     (message "Committing...")
  1493.     (if (cvs-execute-list cc-list cvs-program
  1494.               (if cvs-cvsroot
  1495.                   (list "-d" cvs-cvsroot "commit" "-f" msg-file-name)
  1496.                 (list "commit" "-f" msg-file-name)))
  1497.     (error "Something went wrong. Check the %s buffer carefully."
  1498.            cvs-temp-buffer-name))
  1499.     (let ((ccl cc-list))
  1500.       (while ccl
  1501.     (cvs-after-commit-function (tin-cookie cvs-cookie-handle (car ccl)))
  1502.     (setq ccl (cdr ccl))))
  1503.     (apply 'tin-invalidate cvs-cookie-handle cc-list)
  1504.     (set-buffer msg-buffer)
  1505.     (setq cvs-commit-list nil)
  1506.     (set-buffer cc-buffer)
  1507.     (if cvs-auto-remove-handled
  1508.     (cvs-mode-remove-handled)))
  1509.   (message "Committing... Done."))
  1510.  
  1511.  
  1512. (defun cvs-after-commit-function (fileinfo)
  1513.   "Do everything that needs to be done when FILEINFO has been commited.
  1514. The fileinfo->handle is set, and if the buffer is present it is reverted."
  1515.   (cvs-set-fileinfo->handled fileinfo t)
  1516.   (if cvs-auto-revert-after-commit
  1517.       (let* ((file (cvs-fileinfo->full-path fileinfo))
  1518.          (buffer (get-file-buffer file)))
  1519.     ;; For a revert to happen...
  1520.     (if buffer
  1521.         ;; ...the user must be editing the file...
  1522.         (save-excursion
  1523.           (set-buffer buffer)
  1524.           (if (not (buffer-modified-p))
  1525.           ;; ...but it must be unmodified.
  1526.           (revert-buffer 'dont-use-auto-save-file 'dont-ask)))))))
  1527.  
  1528.  
  1529. (defun cvs-execute-list (tin-list program constant-args)
  1530.   "Run PROGRAM on all elements on TIN-LIST.
  1531. Args: TIN-LIST PROGRAM CONSTANT-ARGS
  1532. The PROGRAM will be called with pwd set to the directory the
  1533. files reside in. CONSTANT-ARGS should be a list of strings. The
  1534. arguments given to the program will be CONSTANT-ARGS followed by all
  1535. the files (from TIN-LIST) that resides in that directory. If the files
  1536. in TIN-LIST resides in different directories the PROGRAM will be run
  1537. once for each directory (if all files in the same directory appears
  1538. after each other).
  1539.  
  1540. Any output from PROGRAM will be inserted in the current buffer.
  1541.  
  1542. This function return nil if all went well, or the numerical exit
  1543. status or a signal name as a string. Note that PROGRAM might be called
  1544. several times. This will return non-nil if something goes wrong, but
  1545. there is no way to know which process that failed."
  1546.  
  1547.   (let ((exitstatus nil))
  1548.     (while tin-list
  1549.       (let ((current-dir (cvs-fileinfo->dir
  1550.               (tin-cookie cvs-cookie-handle
  1551.                      (car tin-list))))
  1552.         arg-list arg-str)
  1553.  
  1554.     ;; Collect all marked files in this directory.
  1555.  
  1556.     (while (and tin-list
  1557.             (string=
  1558.              current-dir
  1559.              (cvs-fileinfo->dir
  1560.               (tin-cookie cvs-cookie-handle (car tin-list)))))
  1561.       (setq arg-list
  1562.         (cons (cvs-fileinfo->file-name
  1563.                (tin-cookie cvs-cookie-handle (car tin-list)))
  1564.               arg-list))
  1565.       (setq tin-list (cdr tin-list)))
  1566.  
  1567.     (setq arg-list (nreverse arg-list))
  1568.  
  1569.     ;; Execute the command on all the files that were collected.
  1570.  
  1571.     (setq default-directory (file-name-as-directory current-dir))
  1572.     (insert (format "=== cd %s\n" default-directory))
  1573.     (insert (format "=== %s %s\n\n"
  1574.             program
  1575.             (mapconcat '(lambda (foo) foo)
  1576.                    (nconc (copy-sequence constant-args)
  1577.                       arg-list)
  1578.                    " ")))
  1579.     (let ((res (apply 'call-process program nil t t
  1580.               (nconc (copy-sequence constant-args) arg-list))))
  1581.       ;; Remember the first, or highest, exitstatus.
  1582.       (if (and (not (and (integerp res) (zerop res)))
  1583.            (or (null exitstatus)
  1584.                (and (integerp exitstatus) (= 1 exitstatus))))
  1585.           (setq exitstatus res)))
  1586.     (goto-char (point-max))))
  1587.     exitstatus))
  1588.  
  1589.  
  1590. (defun cvs-execute-single-file-list (tin-list extractor program constant-args)
  1591.   "Run PROGRAM on all elements on TIN-LIST.
  1592.  
  1593. Args: TIN-LIST EXTRACTOR PROGRAM CONSTANT-ARGS
  1594.  
  1595. The PROGRAM will be called with pwd set to the directory the files
  1596. reside in.  CONSTANT-ARGS is a list of strings to pass as arguments to
  1597. PROGRAM.  The arguments given to the program will be CONSTANT-ARGS
  1598. followed by the list that EXTRACTOR returns.
  1599.  
  1600. EXTRACTOR will be called once for each file on TIN-LIST.  It is given
  1601. one argument, the cvs-fileinfo.  It can return t, which means ignore
  1602. this file, or a list of arguments to send to the program."
  1603.  
  1604.     (while tin-list
  1605.       (let ((default-directory (file-name-as-directory
  1606.                 (cvs-fileinfo->dir
  1607.                  (tin-cookie cvs-cookie-handle
  1608.                         (car tin-list)))))
  1609.         (arg-list
  1610.          (funcall extractor
  1611.               (tin-cookie cvs-cookie-handle (car tin-list)))))
  1612.  
  1613.     ;; Execute the command unless extractor returned t.
  1614.  
  1615.     (if (eq arg-list t)
  1616.         nil
  1617.       (insert (format "=== cd %s\n" default-directory))
  1618.       (insert (format "=== %s %s\n\n"
  1619.               program
  1620.               (mapconcat '(lambda (foo) foo)
  1621.                      (nconc (copy-sequence constant-args)
  1622.                         arg-list)
  1623.                      " ")))
  1624.       (apply 'call-process program nil t t
  1625.          (nconc (copy-sequence constant-args) arg-list))
  1626.       (goto-char (point-max))))
  1627.       (setq tin-list (cdr tin-list))))
  1628.  
  1629.  
  1630. (defun cvs-edit-mode ()
  1631.   "\\<cvs-edit-mode-map>Mode for editing cvs log messages.
  1632. Commands:
  1633. \\[cvs-edit-done] checks in the file when you are ready.
  1634. This mode is based on fundamental mode."
  1635.   (interactive)
  1636.   (use-local-map cvs-edit-mode-map)
  1637.   (setq major-mode 'cvs-edit-mode)
  1638.   (setq mode-name "CVS Log")
  1639.   (auto-fill-mode 1))
  1640.  
  1641.  
  1642. (if cvs-edit-mode-map
  1643.     nil
  1644.   (setq cvs-edit-mode-map (make-sparse-keymap))
  1645.   (define-prefix-command 'cvs-control-c-prefix)
  1646.   (define-key cvs-edit-mode-map "\C-c" 'cvs-control-c-prefix)
  1647.   (define-key cvs-edit-mode-map "\C-c\C-c" 'cvs-edit-done))
  1648.  
  1649.  
  1650. (defun cvs-diffable (tins)
  1651.   "Return a list of all tins on TINS that it makes sense to run
  1652. ``cvs diff'' on."
  1653.   ;; +++ There is an unnecessary (nreverse) here. Get the list the
  1654.   ;; other way around instead!
  1655.   (let ((result nil))
  1656.     (while tins
  1657.       (let ((type (cvs-fileinfo->type
  1658.            (tin-cookie cvs-cookie-handle (car tins)))))
  1659.     (if (or (eq type 'MODIFIED)
  1660.         (eq type 'UPDATED)
  1661.         (eq type 'MERGED)
  1662.         (eq type 'CONFLICT)
  1663.         (eq type 'REMOVED)    ;+++Does this line make sense?
  1664.         (eq type 'ADDED))    ;+++Does this line make sense?
  1665.         (setq result (cons (car tins) result)))
  1666.     (setq tins (cdr tins))))
  1667.     (nreverse result)))
  1668.       
  1669.                      
  1670. (defun cvs-mode-diff-cvs (&optional ignore-marks)
  1671.   "Diff the selected files against the repository.
  1672. The flags in the variable cvs-diff-flags (which should be a list
  1673. of strings) will be passed to ``cvs diff''.  If the variable
  1674. cvs-diff-ignore-marks is non-nil any marked files will not be
  1675. considered to be selected.  An optional prefix argument will invert
  1676. the influence from cvs-diff-ignore-marks."
  1677.  
  1678.   (interactive "P")
  1679.  
  1680.   (if (not (listp cvs-diff-flags))
  1681.       (error "cvs-diff-flags should be a list of strings"))
  1682.  
  1683.   (save-some-buffers)
  1684.   (let ((marked (cvs-diffable
  1685.          (cvs-get-marked
  1686.           (or (and ignore-marks (not cvs-diff-ignore-marks))
  1687.               (and (not ignore-marks) cvs-diff-ignore-marks))))))
  1688.     (cvs-use-temp-buffer)
  1689.     (message "cvsdiffing...")
  1690.     ;; Don't care much about the exit status since it is the _sum_ of
  1691.     ;; the status codes from the different files (not the _max_ as it
  1692.     ;; should be).
  1693.     (if (cvs-execute-list marked cvs-program
  1694.               (if cvs-cvsroot
  1695.                   (cons "-d" (cons cvs-cvsroot
  1696.                            (cons "diff" cvs-diff-flags)))
  1697.                 (cons "diff" cvs-diff-flags)))
  1698.     (message "cvsdiffing... Done.")
  1699.       (message "cvsdiffing... No differences found."))))
  1700.  
  1701.  
  1702. (defun cvs-backup-diffable (tin)
  1703.   "Check if the TIN is backup-diffable.
  1704. It must have a backup file to be diffable."
  1705.   (file-readable-p
  1706.    (cvs-fileinfo->backup-file (tin-cookie cvs-cookie-handle tin))))
  1707.  
  1708. (defun cvs-mode-diff-backup (&optional ignore-marks)
  1709.   "Diff the files against the backup file.
  1710. This command can be used on files that are marked with \"Merged\"
  1711. or \"Conflict\" in the *cvs* buffer.
  1712.  
  1713. If the variable cvs-diff-ignore-marks is non-nil any marked files will
  1714. not be considered to be selected.  An optional prefix argument will
  1715. invert the influence from cvs-diff-ignore-marks.
  1716.  
  1717. The flags in cvs-diff-flags will be passed to ``diff''."
  1718.  
  1719.   (interactive "P")
  1720.  
  1721.   (if (not (listp cvs-diff-flags))
  1722.       (error "cvs-diff-flags should be a list of strings."))
  1723.  
  1724.   (save-some-buffers)
  1725.   (let ((marked (cvs-filter
  1726.          (function cvs-backup-diffable)
  1727.          (cvs-get-marked
  1728.           (or
  1729.            (and ignore-marks (not cvs-diff-ignore-marks))
  1730.            (and (not ignore-marks) cvs-diff-ignore-marks))))))
  1731.     (if (null marked)
  1732.     (error "No ``Conflict'' or ``Merged'' file selected!"))
  1733.     (cvs-use-temp-buffer)
  1734.     (message "diffing...")
  1735.     (cvs-execute-single-file-list
  1736.      marked 'cvs-diff-backup-extractor cvs-diff-program cvs-diff-flags))
  1737.   (message "diffing... Done."))
  1738.  
  1739.  
  1740. (defun cvs-diff-backup-extractor (fileinfo)
  1741.   "Return the filename and the name of the backup file as a list.
  1742. Signal an error if there is no backup file."
  1743.   (if (not (file-readable-p (cvs-fileinfo->backup-file fileinfo)))
  1744.       (error "%s has no backup file."
  1745.          (concat
  1746.           (file-name-as-directory (cvs-fileinfo->dir fileinfo))
  1747.           (cvs-fileinfo->file-name fileinfo))))
  1748.   (list    (cvs-fileinfo->backup-file fileinfo)
  1749.      (cvs-fileinfo->file-name fileinfo)))
  1750.  
  1751. (defun cvs-mode-find-file-other-window (pos)
  1752.   "Select a buffer containing the file in another window.
  1753. Args: POS"
  1754.   (interactive "d")
  1755.   (let ((tin (tin-locate cvs-cookie-handle pos)))
  1756.     (if tin
  1757.     (let ((type (cvs-fileinfo->type (tin-cookie cvs-cookie-handle
  1758.                                 tin))))
  1759.       (cond
  1760.        ((or (eq type 'REMOVED)
  1761.         (eq type 'CVS-REMOVED))
  1762.         (error "Can't visit a removed file."))
  1763.        ((eq type 'DIRCHANGE)
  1764.         (let ((obuf (current-buffer))
  1765.           (odir default-directory))
  1766.           (setq default-directory
  1767.             (file-name-as-directory
  1768.              (cvs-fileinfo->dir
  1769.               (tin-cookie cvs-cookie-handle tin))))
  1770.           (dired-other-window default-directory)
  1771.           (set-buffer obuf)
  1772.           (setq default-directory odir)))
  1773.        (t
  1774.         (find-file-other-window (cvs-full-path tin)))))
  1775.       (error "There is no file to find."))))
  1776.  
  1777. (defun cvs-fileinfo->full-path (fileinfo)
  1778.   "Return the full path for the file that is described in FILEINFO."
  1779.   (concat
  1780.    (file-name-as-directory
  1781.     (cvs-fileinfo->dir fileinfo))
  1782.    (cvs-fileinfo->file-name fileinfo)))
  1783.  
  1784. (defun cvs-full-path (tin)
  1785.   "Return the full path for the file that is described in TIN."
  1786.   (cvs-fileinfo->full-path (tin-cookie cvs-cookie-handle tin)))
  1787.  
  1788. (defun cvs-mode-find-file (pos)
  1789.   "Select a buffer containing the file in another window.
  1790. Args: POS"
  1791.   (interactive "d")
  1792.   (let* ((cvs-buf (current-buffer))
  1793.      (tin (tin-locate cvs-cookie-handle pos)))
  1794.     (if tin
  1795.     (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  1796.            (type (cvs-fileinfo->type fileinfo)))
  1797.       (cond
  1798.        ((or (eq type 'REMOVED)
  1799.         (eq type 'CVS-REMOVED))
  1800.         (error "Can't visit a removed file."))
  1801.        ((eq type 'DIRCHANGE)
  1802.         (let ((odir default-directory))
  1803.           (setq default-directory
  1804.             (file-name-as-directory (cvs-fileinfo->dir fileinfo)))
  1805.           (dired default-directory)
  1806.           (set-buffer cvs-buf)
  1807.           (setq default-directory odir))) 
  1808.        (t
  1809.         (find-file (cvs-full-path tin)))))
  1810.       (error "There is no file to find."))))
  1811.  
  1812. (defun cvs-mode-mark-all-files ()
  1813.   "Mark all files.
  1814. Directories are not marked."
  1815.   (interactive)
  1816.   (cookie-map (function (lambda (cookie)
  1817.               (cond
  1818.                ((not (eq (cvs-fileinfo->type cookie) 'DIRCHANGE))
  1819.                 (cvs-set-fileinfo->marked cookie t)
  1820.                 t))))
  1821.           cvs-cookie-handle))
  1822.  
  1823.  
  1824. (defun cvs-mode-unmark (pos)
  1825.   "Unmark a fileinfo. Args: POS."
  1826.   (interactive "d")
  1827.  
  1828.   (let* ((tin (tin-locate cvs-cookie-handle pos))
  1829.      (sel (tin-cookie cvs-cookie-handle tin)))
  1830.  
  1831.     (cond
  1832.      ((eq (cvs-fileinfo->type sel) 'DIRCHANGE)
  1833.       (cookie-map
  1834.        (function (lambda (f dir)
  1835.            (cond
  1836.             ((cvs-dir-member-p f dir)
  1837.              (cvs-set-fileinfo->marked f nil)
  1838.              t))))
  1839.        cvs-cookie-handle
  1840.        (cvs-fileinfo->dir sel)))
  1841.      (t
  1842.       (cvs-set-fileinfo->marked sel nil)
  1843.       (tin-invalidate cvs-cookie-handle tin)
  1844.       (tin-goto-next cvs-cookie-handle pos 1)))))
  1845.  
  1846. (defun cvs-mode-unmark-all-files ()
  1847.   "Unmark all files.
  1848. Directories are also unmarked, but that doesn't matter, since
  1849. they should always be unmarked."
  1850.   (interactive)
  1851.   (cookie-map (function (lambda (cookie)
  1852.               (cvs-set-fileinfo->marked cookie nil)
  1853.               t))
  1854.           cvs-cookie-handle))
  1855.  
  1856.  
  1857. (defun cvs-do-removal (tins)
  1858.   "Remove files.
  1859. Args: TINS.
  1860. TINS is a list of tins that the
  1861. user wants to delete. The files are deleted. If the type of
  1862. the tin is 'UNKNOWN the tin is removed from the buffer. If it
  1863. is anything else the file is added to a list that should be
  1864. `cvs remove'd and the tin is changed to be of type 'REMOVED.
  1865.  
  1866. Returns a list of tins files that should be `cvs remove'd."
  1867.   (cvs-use-temp-buffer)
  1868.   (mapcar 'cvs-insert-full-path tins)
  1869.   (cond
  1870.    ((and tins (yes-or-no-p (format "Delete %d files? " (length tins))))
  1871.     (let (files-to-remove)
  1872.       (while tins
  1873.     (let* ((tin (car tins))
  1874.            (fileinfo (tin-cookie cvs-cookie-handle tin))
  1875.            (type (cvs-fileinfo->type fileinfo)))
  1876.       (if (not (or (eq type 'REMOVED) (eq type 'CVS-REMOVED)))
  1877.           (progn
  1878.         (delete-file (cvs-full-path tin))
  1879.         (cond
  1880.          ((or (eq type 'UNKNOWN) (eq type 'MOVE-AWAY))
  1881.           (tin-delete cvs-cookie-handle tin))
  1882.          (t
  1883.           (setq files-to-remove (cons tin files-to-remove))
  1884.           (cvs-set-fileinfo->type fileinfo 'REMOVED)
  1885.           (cvs-set-fileinfo->handled fileinfo nil)
  1886.           (tin-invalidate cvs-cookie-handle tin))))))
  1887.     (setq tins (cdr tins)))
  1888.       files-to-remove))
  1889.    (t nil)))
  1890.  
  1891.  
  1892.  
  1893. (defun cvs-mode-remove-file ()
  1894.   "Remove all marked files."
  1895.   (interactive)
  1896.   (let ((files-to-remove (cvs-do-removal (cvs-get-marked))))
  1897.     (if (null files-to-remove)
  1898.     nil
  1899.       (cvs-use-temp-buffer)
  1900.       (message "removing from repository...")
  1901.       (if (cvs-execute-list files-to-remove cvs-program
  1902.                 (if cvs-cvsroot
  1903.                 (list "-d" cvs-cvsroot "remove")
  1904.                   '("remove")))
  1905.       (error "CVS exited with non-zero exit status.")
  1906.     (message "removing from repository... done.")))))
  1907.  
  1908. (defun cvs-mode-undo-local-changes ()
  1909.   "Undo local changes to all marked files.
  1910. The file is removed and `cvs update FILE' is run."
  1911.   (interactive)
  1912.   (let ((tins-to-undo (cvs-get-marked)))
  1913.     (cvs-use-temp-buffer)
  1914.     (mapcar 'cvs-insert-full-path tins-to-undo)
  1915.     (cond
  1916.      ((and tins-to-undo (yes-or-no-p (format "Undo changes to %d files? "
  1917.                          (length tins-to-undo))))
  1918.       (let (files-to-update)
  1919.     (while tins-to-undo
  1920.       (let* ((tin (car tins-to-undo))
  1921.          (fileinfo (tin-cookie cvs-cookie-handle tin))
  1922.          (type (cvs-fileinfo->type fileinfo)))
  1923.         (cond
  1924.          ((or
  1925.            (eq type 'UPDATED) (eq type 'MODIFIED) (eq type 'MERGED)
  1926.            (eq type 'CONFLICT) (eq type 'CVS-REMOVED)
  1927.            (eq type 'REM-CONFLICT) (eq type 'MOVE-AWAY)
  1928.            (eq type 'REMOVED))
  1929.           (if (not (eq type 'REMOVED))
  1930.           (delete-file (cvs-full-path tin)))
  1931.           (setq files-to-update (cons tin files-to-update))
  1932.           (cvs-set-fileinfo->type fileinfo 'UPDATED)
  1933.           (cvs-set-fileinfo->handled fileinfo t)
  1934.           (tin-invalidate cvs-cookie-handle tin))
  1935.  
  1936.          ((eq type 'MOD-CONFLICT)
  1937.           (error "Use cvs-mode-add instead on %s."
  1938.              (cvs-fileinfo->file-name fileinfo)))
  1939.  
  1940.          ((eq type 'REM-CONFLICT)
  1941.           (error "Can't deal with a file you have removed and recreated."))
  1942.  
  1943.          ((eq type 'DIRCHANGE)
  1944.           (error "Undo on directories not supported (yet)."))
  1945.  
  1946.          ((eq type 'ADDED)
  1947.           (error "There is no old revision to get for %s"
  1948.              (cvs-fileinfo->file-name fileinfo)))
  1949.          (t (error "cvs-mode-undo-local-changes: can't handle an %s"
  1950.                type)))
  1951.  
  1952.         (setq tins-to-undo (cdr tins-to-undo))))
  1953.     (cvs-use-temp-buffer)
  1954.     (message "Regetting files from repository...")
  1955.     (if (cvs-execute-list files-to-update cvs-program
  1956.                   (if cvs-cvsroot
  1957.                   (list "-d" cvs-cvsroot "update")
  1958.                 '("update")))
  1959.         (error "CVS exited with non-zero exit status.")
  1960.       (message "Regetting files from repository... done.")))))))
  1961.  
  1962. (defun cvs-mode-acknowledge ()
  1963.   "Remove all marked files from the buffer."
  1964.   (interactive)
  1965.  
  1966.   (mapcar (function (lambda (tin)
  1967.               (tin-delete cvs-cookie-handle tin)))
  1968.       (cvs-get-marked)))
  1969.  
  1970.  
  1971. (defun cvs-mode-unmark-up (pos)
  1972.   "Unmark the file on the previous line.
  1973. Takes one argument POS, a buffer position."
  1974.   (interactive "d")
  1975.   (let ((tin (tin-goto-previous cvs-cookie-handle pos 1)))
  1976.     (cond
  1977.      (tin
  1978.       (cvs-set-fileinfo->marked (tin-cookie cvs-cookie-handle tin)
  1979.                 nil)
  1980.       (tin-invalidate cvs-cookie-handle tin)))))
  1981.  
  1982. (defun cvs-mode-previous-line (arg)
  1983.   "Go to the previous line.
  1984. If a prefix argument is given, move by that many lines."
  1985.   (interactive "p")
  1986.   (tin-goto-previous cvs-cookie-handle (point) arg))
  1987.  
  1988. (defun cvs-mode-next-line (arg)
  1989.   "Go to the next line.
  1990. If a prefix argument is given, move by that many lines."
  1991.   (interactive "p")
  1992.   (tin-goto-next cvs-cookie-handle (point) arg))
  1993.  
  1994. (defun cvs-add-file-update-buffer (tin)
  1995.   "Subfunction to cvs-mode-add. Internal use only.
  1996. Update the display. Return non-nil if `cvs add' should be called on this
  1997. file. Args: TIN.
  1998. Returns 'ADD or 'RESURRECT."
  1999.   (let ((fileinfo (tin-cookie cvs-cookie-handle tin)))
  2000.     (cond
  2001.      ((eq (cvs-fileinfo->type fileinfo) 'UNKNOWN)
  2002.       (cvs-set-fileinfo->type fileinfo 'ADDED)
  2003.       (tin-invalidate cvs-cookie-handle tin)
  2004.       'ADD)
  2005.      ((eq (cvs-fileinfo->type fileinfo) 'REMOVED)
  2006.       (cvs-set-fileinfo->type fileinfo 'UPDATED)
  2007.       (cvs-set-fileinfo->handled fileinfo t)
  2008.       (tin-invalidate cvs-cookie-handle tin)
  2009.       'RESURRECT))))
  2010.  
  2011. (defun cvs-add-sub (cvs-buf candidates)
  2012.   "Internal use only.
  2013. Args: CVS-BUF CANDIDATES.
  2014. CANDIDATES is a list of tins. Updates the CVS-BUF and returns a pair of lists.
  2015. The first list is unknown tins that shall be `cvs add -m msg'ed.
  2016. The second list is removed files that shall be `cvs add'ed (resurrected)."
  2017.   (let (add resurrect)
  2018.     (while candidates
  2019.       (let ((type (cvs-add-file-update-buffer (car candidates))))
  2020.     (cond ((eq type 'ADD)
  2021.            (setq add (cons (car candidates) add)))
  2022.           ((eq type 'RESURRECT)
  2023.            (setq resurrect (cons (car candidates) resurrect)))))
  2024.       (setq candidates (cdr candidates)))
  2025.     (cons add resurrect)))
  2026.  
  2027. (defun cvs-mode-add ()
  2028.   "Add marked files to the cvs repository."
  2029.   (interactive)
  2030.  
  2031.   (let* ((buf (current-buffer))
  2032.      (result (cvs-add-sub buf (cvs-get-marked)))
  2033.      (added (car result))
  2034.      (resurrect (cdr result))
  2035.      (msg (if added (read-from-minibuffer "Enter description: "))))
  2036.  
  2037.     (if (or resurrect added)
  2038.     (cvs-use-temp-buffer))
  2039.  
  2040.     (cond (resurrect
  2041.        (message "Resurrecting files from repository...")
  2042.        (if (cvs-execute-list resurrect cvs-program
  2043.                  (if cvs-cvsroot
  2044.                      (list "-d" cvs-cvsroot "add")
  2045.                    '("add")))
  2046.            (error "CVS exited with non-zero exit status.")
  2047.          (message "Done."))))
  2048.  
  2049.     (cond (added
  2050.        (message "Adding new files to repository...")
  2051.        (if (cvs-execute-list added cvs-program
  2052.                  (if cvs-cvsroot
  2053.                      (list "-d" cvs-cvsroot "add" "-m" msg)
  2054.                    (list "add" "-m" msg)))
  2055.            (error "CVS exited with non-zero exit status.")
  2056.          (message "Done."))))))
  2057.  
  2058. (defun cvs-mode-ignore ()
  2059.   "Arrange so that CVS ignores the selected files.
  2060. This command ignores files that are not flagged as `Unknown'."
  2061.   (interactive)
  2062.  
  2063.   (mapcar (function (lambda (tin)
  2064.               (cond
  2065.                ((eq (cvs-fileinfo->type
  2066.                  (tin-cookie cvs-cookie-handle tin))
  2067.                 'UNKNOWN)
  2068.             (cvs-append-to-ignore
  2069.              (tin-cookie cvs-cookie-handle tin))
  2070.             (tin-delete cvs-cookie-handle tin)))))
  2071.       (cvs-get-marked)))
  2072.  
  2073. (defun cvs-append-to-ignore (fileinfo)
  2074.   "Append the file in fileinfo to the .cvsignore file"
  2075.   (save-window-excursion
  2076.     (set-buffer (find-file-noselect (concat (file-name-as-directory
  2077.                          (cvs-fileinfo->dir fileinfo))
  2078.                         ".cvsignore")))
  2079.     (goto-char (point-max))
  2080.     (if (not (zerop (current-column)))
  2081.     (insert "\n"))
  2082.     (insert (cvs-fileinfo->file-name fileinfo) "\n")
  2083.     (if cvs-sort-ignore-file
  2084.     (sort-lines nil (point-min) (point-max)))
  2085.     (save-buffer)))
  2086.  
  2087. (defun cvs-mode-status ()
  2088.   "Show cvs status for all marked files."
  2089.   (interactive)
  2090.  
  2091.   (save-some-buffers)
  2092.   (let ((marked (cvs-get-marked)))
  2093.     (cvs-use-temp-buffer)
  2094.     (message "Running cvs status ...")
  2095.     (if (cvs-execute-list
  2096.      marked cvs-program
  2097.      (if cvs-cvsroot
  2098.          (cons "-d" (cons cvs-cvsroot (cons "status" cvs-status-flags)))
  2099.        (cons "status" cvs-status-flags)))
  2100.     (error "CVS exited with non-zero exit status.")
  2101.       (message "Running cvs status ... Done."))))
  2102.  
  2103. (defun cvs-mode-log ()
  2104.   "Display the cvs log of all selected files."
  2105.   (interactive)
  2106.  
  2107.   (let ((marked (cvs-get-marked)))
  2108.     (cvs-use-temp-buffer)
  2109.     (message "Running cvs log ...")
  2110.     (if (cvs-execute-list marked cvs-program
  2111.               (if cvs-cvsroot
  2112.                   (cons "-d" (cons cvs-cvsroot
  2113.                            (cons "log" cvs-log-flags)))
  2114.                 (cons "log" cvs-log-flags)))
  2115.     (error "CVS exited with non-zero exit status.")
  2116.       (message "Running cvs log ... Done."))))
  2117.  
  2118. (defun cvs-byte-compile-files ()
  2119.   "Run byte-compile-file on all selected files that end in '.el'."
  2120.   (interactive)
  2121.   (let ((marked (cvs-get-marked)))
  2122.     (while marked
  2123.       (let ((filename (cvs-full-path (car marked))))
  2124.     (if (string-match "\\.el$" filename)
  2125.         (byte-compile-file filename)))
  2126.       (setq marked (cdr marked)))))
  2127.  
  2128. (defun cvs-insert-full-path (tin)
  2129.   "Insert full path to the file described in TIN in the current buffer."
  2130.   (insert (format "%s\n" (cvs-full-path tin))))
  2131.  
  2132.  
  2133. (defun cvs-mode-add-change-log-entry-other-window (pos)
  2134.   "Add a ChangeLog entry in the ChangeLog of the current directory.
  2135. Args: POS."
  2136.   (interactive "d")
  2137.   (let* ((cvs-buf (current-buffer))
  2138.      (odir default-directory))
  2139.     (setq default-directory
  2140.       (file-name-as-directory
  2141.        (cvs-fileinfo->dir
  2142.         (tin-cookie
  2143.          cvs-cookie-handle
  2144.          (tin-locate cvs-cookie-handle pos)))))
  2145.     (if (not default-directory)        ;In case there was no entries.
  2146.     (setq default-directory odir))
  2147.     (add-change-log-entry-other-window)
  2148.     (set-buffer cvs-buf)
  2149.     (setq default-directory odir)))
  2150.  
  2151.  
  2152. (defun print-cvs-tin (foo)
  2153.   "Debug utility."
  2154.   (let ((cookie (tin-cookie cvs-cookie-handle foo))
  2155.     (stream (get-buffer-create "debug")))
  2156.     (princ "==============\n" stream)
  2157.     (princ (cvs-fileinfo->file-name cookie) stream)
  2158.     (princ "\n" stream)
  2159.     (princ (cvs-fileinfo->dir cookie) stream)
  2160.     (princ "\n" stream)
  2161.     (princ (cvs-fileinfo->full-log cookie) stream)
  2162.     (princ "\n" stream)
  2163.     (princ (cvs-fileinfo->marked cookie) stream)
  2164.     (princ "\n" stream)))
  2165.  
  2166. (defun cvs-mode-emerge (pos)
  2167.   "Emerge appropriate revisions of the selected file.
  2168. Args: POS"
  2169.   (interactive "d")
  2170.   (let* ((cvs-buf (current-buffer))
  2171.      (tin (tin-locate cvs-cookie-handle pos)))
  2172.     (if tin
  2173.     (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  2174.            (type (cvs-fileinfo->type fileinfo)))
  2175.       (cond
  2176.        ((eq type 'MODIFIED)
  2177.         (require 'emerge)
  2178.         (let ((tmp-file
  2179.            (cvs-retrieve-revision-to-tmpfile fileinfo)))
  2180.           (unwind-protect
  2181.           (if (not (emerge-files
  2182.                 t
  2183.                 (cvs-fileinfo->full-path fileinfo)
  2184.                 tmp-file
  2185.                 (cvs-fileinfo->full-path fileinfo)))
  2186.               (error "Emerge session failed"))
  2187.         (delete-file tmp-file))))
  2188.  
  2189.        ((or (eq type 'MERGED)
  2190.         (eq type 'CONFLICT))
  2191.         (require 'emerge)
  2192.         (let ((tmp-file
  2193.            (cvs-retrieve-revision-to-tmpfile
  2194.             fileinfo))
  2195.           (ancestor-file
  2196.            (cvs-retrieve-revision-to-tmpfile
  2197.             fileinfo
  2198.             (cvs-fileinfo->base-revision fileinfo))))
  2199.           (unwind-protect
  2200.           (if (not (emerge-files-with-ancestor
  2201.                 t
  2202.                 (cvs-fileinfo->backup-file fileinfo)
  2203.                 tmp-file
  2204.                 ancestor-file
  2205.                 (cvs-fileinfo->full-path fileinfo)))
  2206.               (error "Emerge session failed"))
  2207.         (delete-file tmp-file)
  2208.         (delete-file ancestor-file))))
  2209.        (t
  2210.         (error "Can only emerge \"Modified\", \"Merged\" or \"Conflict\"%s"
  2211.            " files"))))
  2212.       (error "There is no file to emerge."))))
  2213.  
  2214. (defun cvs-retrieve-revision-to-tmpfile (fileinfo &optional revision)
  2215.   "Retrieve the latest revision of the file in FILEINFO to a temporary file.
  2216. If second optional argument REVISION is given, retrieve that revision instead."
  2217.   (let
  2218.       ((temp-name (make-temp-name
  2219.            (concat (file-name-as-directory
  2220.                 (or (getenv "TMPDIR") cvs-tempdir))
  2221.                "pcl-cvs." revision))))
  2222.     (cvs-kill-buffer-visiting temp-name)
  2223.     (if revision
  2224.     (message "Retrieving revision %s..." revision)
  2225.       (message "Retrieving latest revision..."))
  2226.     (let ((res (call-process cvs-shell nil nil nil "-c"
  2227.                  (concat cvs-program " update -p "
  2228.                      (if revision
  2229.                      (concat "-r " revision " ")
  2230.                        "")
  2231.                      (cvs-fileinfo->full-path fileinfo)
  2232.                      " > " temp-name))))
  2233.       (if (and res (not (and (integerp res) (zerop res))))
  2234.       (error "Something went wrong: %s" res))
  2235.  
  2236.       (if revision
  2237.       (message "Retrieving revision %s... Done." revision)
  2238.     (message "Retrieving latest revision... Done."))
  2239.       (find-file-noselect temp-name)
  2240.       temp-name)))
  2241.  
  2242. (defun cvs-fileinfo->backup-file (fileinfo)
  2243.   "Construct the file name of the backup file for FILEINFO."
  2244.   (if (cvs-fileinfo->base-revision fileinfo)
  2245.       (concat cvs-bakprefix (cvs-fileinfo->file-name fileinfo)
  2246.           "." (cvs-fileinfo->base-revision fileinfo))))
  2247.  
  2248. (defun cvs-kill-buffer-visiting (filename)
  2249.   "If there is any buffer visiting FILENAME, kill it (without confirmation)."
  2250.   (let ((l (buffer-list)))
  2251.     (while l
  2252.       (if (string= (buffer-file-name (car l)) filename)
  2253.       (kill-buffer (car l)))
  2254.       (setq l (cdr l)))))
  2255.  
  2256. (defun cvs-change-cvsroot (newroot)
  2257.   "Change the cvsroot."
  2258.   (interactive "DNew repository: ")
  2259.   (if (or (file-directory-p (expand-file-name "CVSROOT" newroot))
  2260.       (y-or-n-p (concat "Warning: no CVSROOT found inside repository."
  2261.                 " Change cvs-cvsroot anyhow?")))
  2262.       (setq cvs-cvsroot newroot)))
  2263.  
  2264. (if (string-match "Lucid" emacs-version)
  2265.     (progn
  2266.       (autoload 'pcl-cvs-fontify "pcl-cvs-lucid")
  2267.       (add-hook 'cvs-mode-hook 'pcl-cvs-fontify)))
  2268.